I'm getting this error:
The property 'PreserveTimestamp' cannot be found on this object. Verify that the property exists and can be set.
At path\OSBU_Broker_Extract02.ps1:14
char:3
+ $session.PreserveTimestamp = $False
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
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.
I'm not sure where I should set my variable, please see my code below:
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "[server IP]"
UserName = "[username]"
Password = ""
SshHostKeyFingerprint = "ssh-rsa 1024 ...="
}
$session = New-Object WinSCP.Session
$session.PreserveTimestamp = $False
try
{
# Connect
$session.Open($sessionOptions)
# Upload
$session.PutFiles("filename.xlsx", "/destination/").Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}