Bharat Bhammar

Bharat Bhammar

  • NA
  • 1
  • 803

I Need To Send File On Server Using SFTP, But It Is Not Work

Mar 1 2016 5:10 AM
I Need To Send File On Server Using SFTP, But It Is Not Work.
 
I have Use WinSCP And Get Error "Network error: Software caused connection abort"
 
my code is below
 
public static int Main()
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "",
UserName = "",
Password = "",
GiveUpSecurityAndAcceptAnySshHostKey = true,
//SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};

using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);

// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;

TransferOperationResult transferResult;
//String filePath = Server.MapPath("Templates/3-FinancialAdvisor.pdf");
transferResult = session.PutFiles(@"C:\Users\keenans", "../Bin/WinSCP.exe", false, transferOptions);

// Throw on any error
transferResult.Check();

// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}

return 0;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return 1;
}
}

 
 
 

Answers (1)