linux - "Upload of file ' ... ' was successful, but error occurred while setting the permissions and/or timestamp"在 PowerShell 中使用 WinSCP .NET 程序集时

标签 linux powershell sftp winscp winscp-net

Exception calling "Check" with "0" argument(s): "Upload of file '2019-06-11.zip'
was successful, but error occurred while setting the permissions and/or
timestamp.
If the problem persists, turn off setting permissions or preserving timestamp.
Alternatively you can turn on 'Ignore permission errors' option.
Permission denied.
Error code: 3
Error message from server: This server does not support operations to modify
file attributes."
At line:12 char:84
+     $session.PutFiles("D:\Users\bin\*.zip", "/Outbox/").Check <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I keep on getting above error file transferring file from Window Server to Linux. I got the same error when using the WinSCP GUI as well. I asked MFT team and they didn't any set permission. Below are my script for file transferring and some of intro version of software I'm using. Anything I missed out for my script or version of software is too old? I will have an update of server soon but have to wait another 2 yrs. This task will be set as scheduler to transfer file daily to MFT server.

Version of software:

  1. Use .NET 4.0
  2. Use PowerShell v2.0
  3. Window Server 2008
  4. Placed private.ppk, WinSCPNet.dll and WinSCP.exe at same folder
#Load WinSCP .NET assembly
Add-Type -Path "D:\Users\WinSCPnet.dll" -Verbose

$session = New-Object WinSCP.Session
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "[Linux server IP]"
$sessionOptions.UserName = "[username]"
$sessionOptions.PortNumber = "[linux port number]"
$sessionOptions.Password = ""
$sessionOptions.SshPrivateKeyPath = "D:\Users\bin.ppk"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 ....="

try {
    # Open the WinSCP.Session object using the WinSCP.SessionOptions object.
    $session.Open($sessionOptions)

    # Upload
    $session.PutFiles("D:\Users\bin\*.zip", "/Outbox/").Check()
} finally {
    # Disconnect, clean up
    $session.Dispose()
}

最佳答案

错误记录在这里:
https://winscp.net/eng/docs/message_preserve_time_perm

您的服务器不支持更新上传的远程文件的时间戳。所以你需要指示 WinSCP 不要尝试它:

$transferOptions = New-Object WinSCP.TransferOptions
...
$transferOptions.PreserveTimestamp = $False

$session.PutFiles("D:\Users\bin\*.zip", "/Outbox/", $False, $transferOptions).Check()

关于linux - "Upload of file ' ... ' was successful, but error occurred while setting the permissions and/or timestamp"在 PowerShell 中使用 WinSCP .NET 程序集时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57164832/

相关文章:

json - 使用 Powershell 查找和替换嵌套的 JSON 值

powershell - 如何使用 PowerShell 读取/写入 App.config 设置?

c# - SSH.NET 库对文件名进行编码

linux - USB 设备的 udev 规则不工作

linux - Bash 脚本 - 迭代查找的输出

powershell - 在Powershell中显示文件的实时内容

java - Commons VFS 和 Java.net.URL - 添加对 "sftp://"协议(protocol)的支持

iphone - iPhone 的 SFTP 库?

c++ - 将目录传递给 g++ 以包含文件的正确标志

c++ - 在 C++ 中使用 system();不起作用