[英]WinSCP upload file to remote SFTP error: “Cannot create remote file – Permission denied”
我們正在使用 FileZilla 從遠程 SFTP 服務器下載和上傳一些手動過程。 使用客戶端軟件,我們沒有任何權限問題。
最近我們決定使用 VB.NET 將其移動到預定函數中。 下載運行良好(所以我從我的代碼中刪除了它,只是為了使代碼示例簡潔)。
但是為了上傳,程序遇到了一個錯誤:
WinSCP.SessionRemoteException: '無法創建遠程文件 '/some path/on/remote/myFile.txt.filepart'。
沒有權限。
錯誤代碼:3
來自服務器的錯誤消息 (en): 權限被拒絕'
下面是上傳文件的代碼。
Using session As New Session
session.Open(sessionOptions)
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary
Dim transferResult As TransferOperationResult
' localFilePath = "C:\somepath\myFile.txt"
If Not String.IsNullOrEmpty(localFilePath) And File.Exists(localFilePath) Then
transferResult = session.PutFiles(localFilePath, "/some path/on/remote/", False, transferOptions)
transferResult.Check() 'error was thrown here
Else
Throw New FileNotFoundException("The file could not be found")
End If
End Using
任何幫助表示贊賞,感謝您的時間。
使用 SFTP 協議,WinSCP 默認通過臨時文件傳輸超過 100 KB的文件。 如果您沒有創建新文件的權限,這將不起作用。
在這種情況下,您需要通過臨時文件(又名可恢復傳輸)禁用傳輸。 對於該設置TransferOptions.ResumeSupport
:
Dim transferOptions As New TransferOptions
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off
transferResult =
session.PutFiles(localFilePath, "/remote/path/", False, transferOptions)
transferResult.Check()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.