我们使用FileZilla进行了一些手动过程,从远程SFTP服务器下载并上传到远程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:somepathmyFile.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默认情况下通过临时文件传输超过100KB的文件。如果您没有创建新文件的权限,这将不起作用。
在这种情况下,您需要通过临时文件禁用传输(也称为可恢复传输(。对于该集合TransferOptions.ResumeSupport
:
Dim transferOptions As New TransferOptions
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off
transferResult =
session.PutFiles(localFilePath, "/remote/path/", False, transferOptions)
transferResult.Check()