Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: SFTP using

Your code is correct in general. What's the PortNumber? Why do you set it? Does your server use a non-default port number?
Can you connect in WinSCP GUI or anyhow?

SFTP using

In my solution development I have a requirement to perform SFTP File Upload using public key. System should be able to transfer the data using Host, Port, UserName, and Public Key. No Password is required. How can I achieve this using WinSCP .net assembly. I tried the below code. But I am getting Connection TimeOut exception.

public bool TestConnection()
//SessionOptions sessionOptions = BuildSFTPSessionOptions();
// Setup session options
SessionOptions sessionOptions = new SessionOptions
Protocol = Protocol.Sftp,
HostName = this.Host,
PortNumber = this.Port,
UserName = this.UserName,
Password = this.Password,
SshPrivateKeyPath = this.PrivateKeyPath,
FtpMode = FtpMode.Passive,
SshHostKeyFingerprint="ssh-rsa 2048 17:e3:bd:e6:60:f2:75:59:27:44:e3:04:0c:b7:e6:51"
using (Session session = new Session())
// Connect
// Move files
return true;

return false;
catch (Exception ex)
throw ex;