tags:

views:

3670

answers:

8

Does this capability come with .Net? If not, what's the best free library? I need something that will throw good exceptions when there is a problem, and allows me to monitor its progress.

A: 

There is no solution for this within the .net framework.

http://www.eldos.com/sbb/sftpcompare.php outlines a list of un-free options.

your best free bet is to extend SSH using Granados. http://www.routrek.co.jp/en/product/varaterm/granados.html

ddc0660
A: 

Unfortunately, it's not in the .NET Framework itself. My wish is that you could integrate with FileZilla, but I don't think it exposes an interface. They do have scripting I think, but it won't be as clean obviously.

I've used CuteFTP in a project which does SFTP. It exposes a COM component which I created a .NET wrapper around. The catch, you'll find, is permissions. It runs beautifully under the Windows credentials which installed CuteFTP, but running under other credentials requires permissions to be set in DCOM.

Mike L
+1  A: 

Maybe you can script/control winscp?

Kasprzol
Good point. I found a guide to doing exactly that: http://winscp.net/eng/docs/guide_dotnet
Raithlin
+7  A: 

You may want to take a look a SharpSSH. It supports SFTP out of the box and it's OpenSource.

Ryan Lanciaux
SharpSSH appears to be based on Java libraries (JSch and JCE) and browsing the extensive source code did not make me confident that this library can be used in a production environment. A little stress testing resulted in unexpected exceptions.
Martin Liversage
A: 

For another un-free option try edtFTPnet/PRO. It has comprehensive support for SFTP, and also supports FTPS (and of course FTP) if required.

Bruce Blackshaw
A: 

Corey,

I just created a C# SFTP Library. Try it out and let me know what you think.

Thanks, Greg

Greg Finzer
This seems to be a commercial product based on SharpSSH. And after having looked at the SharpSSH source code I don't trust it too much.
Martin Liversage
We corrected the defects in the SharpSSH library and created hundreds of nunit tests to verify that everything is working correctly.
Greg Finzer
A: 

Following code shows how to upload a file to a SFTP server using our Rebex SFTP component.

// create client, connect and log in 
Sftp client = new Sftp();
client.Connect(hostname);
client.Login(username, password);

// upload the 'test.zip' file to the current directory at the server 
client.PutFile(@"c:\data\test.zip", "test.zip");

client.Disconnect();

You can write a complete communication log to a file using a LogWriter property as follows. Examples output (from FTP component but the SFTP output is similar) can be found here.

client.LogWriter = new Rebex.FileLogWriter(
   @"c:\temp\log.txt", Rebex.LogLevel.Debug); 

or intercept the communication using events as follows:

Sftp client = new Sftp();
client.CommandSent += new SftpCommandSentEventHandler(client_CommandSent);
client.ResponseRead += new SftpResponseReadEventHandler(client_ResponseRead);
client.Connect("sftp.example.org");

//... 
private void client_CommandSent(object sender, SftpCommandSentEventArgs e)
{
    Console.WriteLine("Command: {0}", e.Command);
}

private void client_ResponseRead(object sender, SftpResponseReadEventArgs e)
{
    Console.WriteLine("Response: {0}", e.Response);
}

For more info see tutorial or download a trial and check samples.

Martin Vobr
My limited testing of various .NET SFTP clients indicates that this commercial product is good choice.
Martin Liversage
I've used the RebEx stuff before also when I needed to use it for an SSIS package. They have good support and documentation if you are looking to go via a commercial 3rd party route.
D.S.
A: 

Though not free, it is definitely the best investment I ever made for my company besides buying Visual Studio. You can take a look at chilkat's implementation below:

http://www.example-code.com/csharp/sftp_uploadFile.asp

http://www.cknotes.com/?p=199

Anthony Greco