gpt4 book ai didi

.net - WinSCP上传文件到远程SFTP错误: "Cannot create remote file – Permission denied"

转载 作者:行者123 更新时间:2023-12-04 10:28:04 26 4
gpt4 key购买 nike

我们正在执行一些手动过程,使用 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 协议(protocol),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()

关于.net - WinSCP上传文件到远程SFTP错误: "Cannot create remote file – Permission denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60550643/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com