使用WinSCP的.NET程序集上傳文件。 OperationResultBase.Check()
拋出以下錯誤:WinSCP:如何確保SFTP上傳從.zip.filepart重命名爲.zip?
WinSCP.SessionRemoteException: Transfer was successfully finished, but temporary transfer file 'testfile.zip.filepart' could not be renamed to target file name 'testfile.zip'. If the problem persists, you may want to turn off transfer resume support.
看來,出現這種情況與我嘗試發送任何zip文件。如果它有所作爲,這些是使用DotNetZip庫創建的zip文件。
代碼,我用的WinSCP賦予文檔中幾乎直接從例如採取:
public void uploadFile(string filePath, string remotePath)
{
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = currentSession.PutFiles(filePath, remotePath, false, transferOptions);
transferResult.Check();
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}
Discussion over at the WinSCP forum表示該組件還不允許轉移開支持編程控制。有沒有解決方法?
這似乎很奇怪,我認爲上載使用不同的文件名比實際所需的文件名。你有控制權嗎? – sarnold
@sarnold,來自WinSCP文檔:「當使用SFTP協議傳輸文件時,它首先傳輸到一個帶有.filepart擴展名的臨時文件中,只有在傳輸完成後,擴展才會被刪除。 – sigil
如果您有權訪問服務器,是否可以從SysInternals運行諸如Process monitor之類的東西來查看文件上傳完成後會發生什麼。例如,防病毒程序可能會在文件關閉時開始掃描文件,並且在嘗試重命名時仍然訪問該文件。 – sgmoore