I am working on an application in which I am downloading files using WinSCP .NET assembly (version 5.5.0.3839)
My code to download file is given below
public bool ReceiveFile(string ftpFilePath,out String downloadedFileName, String DestinationPath)
{
bool sendingStatus = false;
downloadedFileName = string.Empty;
try
{
if (sessionOptions != null)
{
using (Session session = new Session())
{
// Connect
bool isSessionOpened = OpenSession(session);
if (isSessionOpened)
{
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Automatic;
TransferOperationResult transferResult;
transferResult = session.GetFiles(ftpFilePath, DestinationPath, false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
sendingStatus = true;
downloadedFileName = transfer.FileName;
//We are breaking here because we are assuming that for one import batch setup only one file will be downloaded
break;
}
}
}
}
}
catch (Exception ex)
{
}
return sendingStatus;
}
FTP is working fine, but working with SFTP it requires host key.
When I worked with WinSCP application directly it warns for the host key and user is able to copy host key by clicking on "Copy key" button.
Host key will be copied to clipboard and we can use this key to download files from SFTP or SCP.
There is also an option that user can suppress the use of host key.
I want to suppress the use of host key programmatically.
Let me know if there required any other information.