WinSCP 放置文件失败代码 2 但通过 File.Exists
WinSCP Putting Files fails Code 2 but Passes File.Exists
我注意到,当我使用 WinSCP 去 PUT 一个文件时,它失败并出现代码 2 错误,指出:
{WinSCP.SessionRemoteException: File or folder 'fileToPut.xml' does not exist. ---> WinSCP.SessionRemoteException: System Error.
Code: 2. The system cannot find the file specified
--- End of inner exception stack trace ---
at WinSCP.OperationResultBase.Check()
at transferWinSCP(String fileName) in c:\Program.cs:line 136}
然而,就在它到达这一行之前:
TransferOperationResult transferResult = session.PutFiles(fileName, path, false, transferOptions);`
我确定 fileName 确实存在。
有什么想法吗?
这是我的代码:
using (Session session = new Session())
{
//start Log
session.SessionLogPath = logPath;
//connect
session.Open(sessionOptions);
//upload
TransferOptions transferOptions = new TransferOptions {TransferMode = TransferMode.Binary};
if (File.Exists(fileName))
{
TransferOperationResult transferResult = session.PutFiles(fileName, path, false, transferOptions); //put the file on the ftp server
transferResult.Check();
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.Write("upload of {0} succeeded", transfer.FileName);
}
}
}
我目前遇到了同样的问题。
但是我发现如果你改变路径而不是使用“\”尝试“/”有时会得到不同的结果。我想你可能想试一试。但目前改变它对我没有帮助,所以我被困在同一条船上。
这最终对我有用:Path.GetFullPath(fileName)
我注意到,当我使用 WinSCP 去 PUT 一个文件时,它失败并出现代码 2 错误,指出:
{WinSCP.SessionRemoteException: File or folder 'fileToPut.xml' does not exist. ---> WinSCP.SessionRemoteException: System Error.
Code: 2. The system cannot find the file specified
--- End of inner exception stack trace ---
at WinSCP.OperationResultBase.Check()
at transferWinSCP(String fileName) in c:\Program.cs:line 136}
然而,就在它到达这一行之前:
TransferOperationResult transferResult = session.PutFiles(fileName, path, false, transferOptions);`
我确定 fileName 确实存在。
有什么想法吗?
这是我的代码:
using (Session session = new Session())
{
//start Log
session.SessionLogPath = logPath;
//connect
session.Open(sessionOptions);
//upload
TransferOptions transferOptions = new TransferOptions {TransferMode = TransferMode.Binary};
if (File.Exists(fileName))
{
TransferOperationResult transferResult = session.PutFiles(fileName, path, false, transferOptions); //put the file on the ftp server
transferResult.Check();
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.Write("upload of {0} succeeded", transfer.FileName);
}
}
}
我目前遇到了同样的问题。 但是我发现如果你改变路径而不是使用“\”尝试“/”有时会得到不同的结果。我想你可能想试一试。但目前改变它对我没有帮助,所以我被困在同一条船上。
这最终对我有用:Path.GetFullPath(fileName)