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

"Upload of file '...' was successful, but error occurred while setting the permissions and/or timestamp" when using WinSCP .NET assembly in PowerShell

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

我不断收到上述错误文件,将文件从 Window 服务器传输到 Linux。我在使用 WinSCP GUI 时也遇到了同样的错误。我问了 MFT 团队,他们没有任何设置许可。下面是我的文件传输脚本和我正在使用的一些软件介绍版本。我错过了我的脚本或软件版本太旧的任何东西吗?我很快就会更新服务器,但还得再等 2 年。此任务将设置为计划程序,每天将文件传输到 MFT 服务器。

软件版本:

  1. 使用 .NET 4.0
  2. 使用 PowerShell v2.0
  3. Window 服务器 2008
  4. private.ppkWinSCPNet.dllWinSCP.exe 放在同一文件夹中
#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()