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 .
Martin Vobr Jun 16 2018-10-06T00: 00Z
source share