简体   繁体   English

WinSCP 上传文件到远程 SFTP 错误:“无法创建远程文件 - 权限被拒绝”

[英]WinSCP upload file to remote SFTP error: “Cannot create remote file – Permission denied”

We were doing some manual process to download from and upload to a remote SFTP server with FileZilla.我们正在使用 FileZilla 从远程 SFTP 服务器下载和上传一些手动过程。 With the client software we didn't have any permission issues.使用客户端软件,我们没有任何权限问题。

Recently we decided to move it to a scheduled function using VB.NET.最近我们决定使用 VB.NET 将其移动到预定函数中。 The downloading worked well (so I removed it from my code just to make the code sample concise).下载运行良好(所以我从我的代码中删除了它,只是为了使代码示例简洁)。

But for uploading, the program ran into an error:但是为了上传,程序遇到了一个错误:

WinSCP.SessionRemoteException: 'Cannot create remote file '/some path/on/remote/myFile.txt.filepart'. WinSCP.SessionRemoteException: '无法创建远程文件 '/some path/on/remote/myFile.txt.filepart'。

Permission denied.没有权限。

Error code: 3错误代码:3

Error message from server (en): Permission denied'来自服务器的错误消息 (en): 权限被拒绝'

Below is the code for uploading the file.下面是上传文件的代码。

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

Any help is appreciated, thank you for your time.任何帮助表示赞赏,感谢您的时间。

With SFTP protocol, WinSCP by default transfers files over 100 KB via a temporary file .使用 SFTP 协议,WinSCP 默认通过临时文件传输超过 100 KB的文件 That won't work if you do not have permissions to create a new file.如果您没有创建新文件的权限,这将不起作用。

In such case, you will need to disable the transfer via a temporary file (aka resumable transfer).在这种情况下,您需要通过临时文件(又名可恢复传输)禁用传输。 For that set TransferOptions.ResumeSupport :对于该设置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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM