Re: transfer.Options File Permissions
I have added this question to FAQ:
https://winscp.net/eng/docs/faq_library_parameters
https://winscp.net/eng/docs/faq_library_parameters
So the code should be:$session.PutFiles($localPath, $remotePath, $False, $transferOptions)
TransferOptions options
is the 4th argument of Session.PutFiles
$session.PutFiles($localPath, $remotePath, $False, $transferOptions)
< 2019-02-28 10:23:16.188 Error message from server: This server does not support operations to modify file attributes. File attributes for [/Inbox/move_me.xml] were not modified.
* 2019-02-28 10:23:16.189 (ESkipFile) **Upload of file 'move_me.xml' was successful, but error occurred while setting the permissions and/or timestamp.**
* 2019-02-28 10:23:16.189
* 2019-02-28 10:23:16.189 If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore permission errors' option.
* 2019-02-28 10:23:16.189 Permission denied.
try
{
# Connect
$session.Open($sessionOptions)
# Set options, upload files, collect results
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FilePermissions = $Null
$transferOptions.PreserveTimestamp = $False
$transferResult = $session.PutFiles($localPath, $remotePath, $transferOptions)
# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host "Upload of $($transfer.FileName) succeeded, moving to backup"
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $successPath
}
else
{
Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)"
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
PS C:\Users\xxxxxx> $transferOptions
PreserveTimestamp : False
FilePermissions :
TransferMode : Binary
FileMask :
ResumeSupport : default
SpeedLimit : 0
OverwriteMode : Overwrite