我正在使用 WinSCP .NET 程序集(版本 5.5.0.3839)下载文件的应用程序
我下载文件的代码如下
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 工作正常,但使用 SFTP 需要主机密钥。
当我直接使用 WinSCP 应用程序时,它会警告主机密钥,用户可以通过单击“复制密钥”按钮来复制主机密钥。
主机密钥将被复制到剪贴板,我们可以使用此密钥从 SFTP 或 SCP 下载文件。
还有一个选项,用户可以禁止使用主机密钥。
我想以编程方式禁止使用主机密钥。
让我知道是否需要任何其他信息。