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?
When a client system requests a file transfer, SFTP creates a secure connection between the client and the SFTP server. This connection usually goes through port 22. SFTP then uses the SSH protocol to encrypt the requested file and transfer it to the client.
Maybe you can script/control winscp?
Update: winscp now has a .NET library available as a nuget package that supports SFTP, SCP, and FTPS
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With