[SOLVED] 'PreserveTimestamp = $false' not working -- PowerShell script
I am setting up a new job and the host is a bit more restrictive than others I've worked with. I'm continually running into the error below even though I've added the setting to not
The script is basic:
Oddly, it appears that the transfer option to not preserve timestamp is being ignored, according to the log:
I can provide additional log detail if necessary.
I have also tried using these transfer options:
Version:
PreserveTimestamp
.
Error: Exception calling "Check" with "0" argument(s): "**Upload of file 'somefile.txt' 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. The server does not support the operation. Error code: 8 Error message from server (US-ASCII): SETSTAT unsupported"
try { # Load WinSCP .NET assembly Add-Type -Path "c:\TEST\WinSCP\WinSCPnet.dll" # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "somehost.somedomain.com" UserName = "username" Password = "password" GiveUpSecurityAndAcceptAnySshHostKey = $True } $session = New-Object WinSCP.Session $session.SessionLogPath = "C:\TEST\WinSCP\Logs\winscp.log" $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.FilePermissions = $Null # This is default $transferOptions.PreserveTimestamp = $false try { # Connect $session.Open($sessionOptions) $remotePath = "./" $localpath = "\\networkpath\sharename\directory\" $files = @( ("somefile.txt"), ("somefile2.txt"), ("somefile3.txt"), ("somefile4.txt"), ("somefile5.txt") ) foreach ($file in $files) { Write-Host "Uploading $file ..." $session.PutFiles($localpath + $file, $remotePath, $transferOptions).Check() } } finally { # Disconnect, clean up $session.Dispose() } } catch { Write-Host "Error: $($_.Exception.Message)" }
> DATE TIME Script: put -delete -nopermissions -preservetime -transfer="binary" -- "\\networkpath\sharename\directory\somefile.txt" "./"
I have also tried using these transfer options:
$transferOptions.AddRawSettings("IgnorePermErrors", "1") $transferOptions.AddRawSettings("PreserveTimeDirs", "0")
WinSCP Version 5.17.8 (Build 10803) (OS 10.0.17763 - Windows Server 2019 Standard)
Last edited by coffeecoffeecoffee on 2020-10-30 20:47; edited 1 time in total