I am using SSH.NET to download file from the SFTP and here is my code:
string host = ConfigurationManager.AppSettings["SFTPDomain"];
string username = ConfigurationManager.AppSettings["SFTPUser"];
string password = ConfigurationManager.AppSettings["SFTPPass"];
string remoteFileName = ConfigurationManager.AppSettings["SFTPFileName"].ToString();
using (var sftp = new SftpClient(host, username, password))
{
sftp.Connect();
using (var file = File.OpenWrite(FilePath))
{
sftp.DownloadFile(remoteFileName, file);
}
sftp.Disconnect();
}
The problem is that the file which is csv is downloaded but it does not have any data inside. I changed the remoteFile path as well but still the file is downloaded with null data inside. I tried to check if file exists using
if (sftp.Exists(remoteFileName))
{
}
It always return true even if I change the remoteFileName with "pp".
Can anyone help me what I am doing wrong? Or recommend me another other library to download file from SFTP server. I have tried WinSCP but I am getting hostkey error so I tried to pass correct SshHostKeyFingerprint as guided by the server tutorial. Still I get the hostkey error. Is there any simple library i just need to download file from the SFTP?
HostKeyReceivedevent and verify the host key. Key verification is enforced by WinSCP to upkeep security.