I can connect to SFTP using the FileZilla in a machine, in the same machine when I try to connect via C# code it gives error as
Network error: Connection to "fs2.comparethemarket.com" timed out
SFTP port used for connection;2222
Code I am using
SessionOptions sessionOptions = new SessionOptions();
if (_strftpprotocol=="SFTP")
{
sessionOptions.Protocol = WinSCP.Protocol.Sftp;
}
else if(_strftpprotocol == "FTP")
{
sessionOptions.Protocol = WinSCP.Protocol.Ftp;
sessionOptions.FtpSecure = FtpSecure.Explicit;
}
sessionOptions.HostName = _strftpURL;
sessionOptions.UserName = _strftpUserName;
sessionOptions.Password = _strftpPassword;
if (_strftpprotocol == "SFTP")
{
if (string.IsNullOrEmpty(_strftpSSHKey))
{
if (string.IsNullOrEmpty(_strftpKeyPath))
{
sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = true;
}
else
{
privatekeyFilePath = privatekeyFilePath + _strftpKeyPath;
sessionOptions.SshPrivateKeyPath = privatekeyFilePath;
if (!string.IsNullOrEmpty(_strFTPPrivateKeyPassphrase))
{
sessionOptions.PrivateKeyPassphrase = _strFTPPrivateKeyPassphrase;
}
if (!string.IsNullOrEmpty(_strFTPSshHostKeyFingerprint))
{
sessionOptions.SshHostKeyFingerprint = _strFTPSshHostKeyFingerprint;
}
}
}
else
{
if (string.IsNullOrEmpty(_strftpKeyPath))
{
sessionOptions.SshHostKeyFingerprint = _strftpSSHKey;
}
else
{
privatekeyFilePath = privatekeyFilePath + _strftpKeyPath;
sessionOptions.SshPrivateKeyPath = privatekeyFilePath;
if (!string.IsNullOrEmpty(_strFTPPrivateKeyPassphrase))
{
sessionOptions.PrivateKeyPassphrase = _strFTPPrivateKeyPassphrase;
}
if (!string.IsNullOrEmpty(_strFTPSshHostKeyFingerprint))
{
sessionOptions.SshHostKeyFingerprint = _strFTPSshHostKeyFingerprint;
}
}
}
}
Session session = new Session();
session.Open(sessionOptions);
Please guide me what I am doing wrong