WinSCP upload file to remote SFTP error: "Cannot create remote file – Permission denied"

WinSCP upload file to remote SFTP error: "Cannot create remote file – Permission denied"

我们正在执行一些手动过程,使用 FileZilla 从远程 SFTP 服务器下载和上传。使用客户端软件,我们没有任何权限问题。

最近我们决定使用 VB.NET 将其移动到预定函数。下载效果很好(所以我从我的代码中删除它只是为了使代码示例简洁)。

但是为了上传,程序运行出错:

WinSCP.SessionRemoteException: 'Cannot create remote file '/some path/on/remote/myFile.txt.filepart'.

Permission denied.

Error code: 3

Error message from server (en): Permission denied'

下面是上传文件的代码。

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 的文件via a temporary file。如果您没有创建新文件的权限,那将不起作用。

在这种情况下,您需要通过临时文件禁用传输(也称为可恢复传输)。对于那个集合 TransferOptions.ResumeSupport:

Dim transferOptions As New TransferOptions
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off

transferResult =
    session.PutFiles(localFilePath, "/remote/path/", False, transferOptions)
transferResult.Check()