How to upload a file to an SFTP server in C # /. NET?

Is this feature included in .Net? If not, what is the best free library? I need something that will throw good exceptions when there is a problem, and allows me to monitor its progress.

+62
c # sftp
Sep 17 '08 at 19:02
source share
6 answers

Edit: This answer has long been and is no longer valid. See Comments

You can watch SharpSSH . It supports SFTP out of the box and is OpenSource.

+23
Sep 17 '08 at 19:09
source share

Perhaps you can script / control winscp ?

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

+31
Sep 17 '08 at 19:09
source share

The following code shows how to upload a file to an 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 the LogWriter property as follows. Examples of output (from the FTP component, but the SFTP output are similar) can be found here .

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

or intercept the connection 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 information, see the tutorial or download the trial version and test samples .

+7
Jun 16 2018-10-06T00:
source share

There is no solution inside the .NET Framework.

http://www.eldos.com/sbb/sftpcompare.php describes a list of non-free parameters.

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

+2
Sep 17 '08 at 19:07
source share

Unfortunately, this is not in the .NET Framework itself. My wish is that you can integrate with FileZilla, but I don't think it provides an interface. I think they have scripts, but it will not be as clean as obvious.

I used CuteFTP in a project that does SFTP. It provides the COM component that I created the .NET wrapper. The catch, you find, is permission. It works fine under the Windows credentials that installed CuteFTP, but it requires permissions to install under DCOM to use other credentials.

0
Sep 17 '08 at 19:09
source share

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

0
May 19 '09 at 2:23 a.m.
source share



All Articles