Topic "SFTP using WindSCP.net"

Author Message
kalyan_gvk
[View user's profile]

Joined: 2016-08-17
Posts: 1
Location: India
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;
}
}
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
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?
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License