WinSCP PutFileToDirectory 说远程文件不存在但确实存在

WinSCP PutFileToDirectory says the remote file does not exist but it Does

我从 WinSCP 收到一个错误,指出该文件在方法 Session.PutFileToDirectory 中不存在。但实际上该文件确实存在于此调用上方的行中,我对同一文件进行了 GetFileInfo 并且它工作得很好。所以错误被隔离到PutFileToDirectory。但是我不知道如何调试这个或者可能是什么错误。

WinSCP.Session session = new WinSCP.Session();

string LocalDirectory = @"O:\FISCAL SVS\FILES\WStorey\automation\sftp\mcpay\";
string RemoteDirectory = @"";
string RemoteFileName = @"";
string RemoteFilePath = string.Format(@"{0}/{1}", RemoteDirectory, RemoteFileName);

int Protocol = 1;
int PortNumber = 22;
string HostName = "";
string UserName = "";
string Password = "";
string Fingerprint = "";

WinSCP.SessionOptions options = new WinSCP.SessionOptions()
{
    Protocol = (WinSCP.Protocol)Protocol,
    PortNumber = PortNumber,
    HostName = HostName,
    UserName = UserName,
    Password = Password,
    SshHostKeyFingerprint = Fingerprint
};

session.Open(options);

WinSCP.RemoteFileInfo fileInfo = session.GetFileInfo(RemoteFilePath);
session.PutFileToDirectory(RemoteFilePath, LocalDirectory);

session.Close();

您的代码有误。很难说错在哪里,因为您没有告诉我们您希望代码做什么。从您在操作前检查远程文件存在的事实来看,我猜想您要下载远程文件。但是 Session.PutFileToDirectory 上传 一个文件。如果要下载文件,请使用 Session.GetFileToDirectory:

session.GetFileToDirectory(RemoteFilePath, LocalDirectory);