My Code(few data are intentionally changed as "xxx.." for security reason ):-
public void SFtp_Connect()
{
Sftp sftp = new Sftp();
//sftp.Connect("xxx.xxx.x.xx", 22);
//sftp.Login("xxx", "xxx");
////string sourceFilePath = @"C:\testFile\";
//string sourceFilePath = @"C:\test_ftp\ExportList";
//string targetPath = @"Test_Sftp";
//string targetFilename = "";
//sftp.Connect("xxx.xxx.com", 22);
//sftp.Login("xxx", "xxx");
sftp.Connect("xx.xxx.xx.xx", 22);
sftp.Login("xxx", "xxx");
string sourceFilePath = @"C:\Test\ExportList";
string targetPath = @"/out/reports";
string targetFilename = "";
try
{
foreach (string UploadFile in Files)
{
//if (!sftp.DirectoryExists(targetPath))
//sftp.CreateDirectory(targetPath);
sourceFilePath = sourceFilePath + "\\" + UploadFile;
targetFilename = targetFilename + UploadFile;
sftp.GetFile(sourceFilePath, UploadFile);
//sftp.PutFile(sourceFilePath, targetPath + "/" + targetFilename);
}
}
catch (Exception e)
{
throw e;
}
sftp.Disconnect();
}
Error I got :-
2/23/2017 2:49:47 PM : Error on load, Error: Error while sending packet.. Inner Exception:Rebex.Net.SshException: Error while sending packet. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at Rebex.Net.ProxySocket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at Rebex.Net.SshSession.clmbOg(BBdsJfZ , Boolean )
--- End of inner exception stack trace ---
at Rebex.Net.SshSession.clmbOg(BBdsJfZ , Boolean )
at Rebex.Net.SshSession.CgoKrJZ()
at Rebex.Net.SshSession.cCIjvV(String , String , SshPrivateKey , SshGssApiCredentials )
at Rebex.Net.SshSession.Authenticate(String userName, String password, SshPrivateKey privateKey)
at Rebex.Net.Sftp.Login(String userName, String password, SshPrivateKey privateKey). StackTrace: at Rebex.Net.Sftp.Login(String userName, String password, SshPrivateKey privateKey)
at xxx.Form1.SFtpConnectxxx() in d:\Projects\xxx\xxx\xxx\Form1.cs:line 216
at xxx.Form1.Form1_Load(Object sender, EventArgs e) in d:\Projects\xxx\xxx\xxx\Form1.cs:line 103