SFTP using WindSCP.net

Advertisement

kalyan_gvk
Joined:
Posts:
1
Location:
India

SFTP using WindSCP.net

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()
{
try
{
//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
session.Open(sessionOptions);
// Move files
if(session.Opened==true)
{
return true;
}
}

return false;
}
catch (Exception ex)
{
throw ex;
}
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

Re: SFTP using WindSCP.net

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?

Reply with quote

Advertisement

You can post new topics in this forum