71

Does a free .NET library exist with which I can upload a file to a SFTP (SSH FTP) server, which throws exceptions on problems with the upload and allows the monitoring of its progress?

palswim
  • 11,856
  • 6
  • 53
  • 77
Corey
  • 14,101
  • 7
  • 38
  • 35
  • see also the questions [SFTP Libraries for .NET](http://stackoverflow.com/questions/530330/sftp-libraries-for-net) and [FTP/SFTP module for .NET](http://stackoverflow.com/questions/2731967/ftp-sftp-module-for-net) – Jeroen K Feb 04 '14 at 13:01
  • 2
    Another alternative is Renci SSH.NET. – CodesInChaos Feb 03 '15 at 14:35
  • **Edit: this answer is from a long time ago and is no longer valid. See comments** You may want to take a look a [SharpSSH](http://sourceforge.net/projects/sharpssh). It supports SFTP out of the box and it's OpenSource. – Ryan Lanciaux Sep 17 '08 at 19:09

5 Answers5

42

Maybe you can script/control winscp?

Update: winscp now has a .NET library available as a nuget package that supports SFTP, SCP, and FTPS

Aaron
  • 1,390
  • 1
  • 16
  • 30
Kasprzol
  • 4,087
  • 22
  • 20
8

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
  • 5,757
  • 2
  • 37
  • 43
  • 1
    My limited testing of various .NET SFTP clients indicates that this commercial product is good choice. – Martin Liversage Jun 17 '10 at 11:08
  • 2
    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. Oct 08 '10 at 18:08
2

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
  • 4,022
  • 2
  • 21
  • 30
0

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
  • 4,693
  • 5
  • 33
  • 52
0

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
  • 986
  • 1
  • 7
  • 10