tomohulk / WinSCP

WinSCP PowerShell Wrapper Module
GNU General Public License v3.0
156 stars 30 forks source link

Question - Ignore permission errors #87

Closed LostLogic closed 6 years ago

LostLogic commented 6 years ago

I'm sorry for ignoring the issue template, but seeing as this is more of the question I hope you'll forgive me.

I'm uploading files to a bank, and due to constrained rights when doing so, I get a Session Exception that I'm having a hard time negating.

Send-WinSCPItem : WinSCP.SessionRemoteException: Upload of file '' 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. File attributes for [//] were not modified. At line:1 char:11

  • $result = Send-WinSCPItem -WinSCPSession $session -RemotePath $sftpUp ...
  • 
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Send-WinSCPItem

I can't find the Ignore Permissions Error option anywhere as a switch to enable or an option in Transfer Options. Is it hidden somewhere, are there any tricks I can do to negate this issue so I get a result per file sent that I can error check before archiving the files sent etc? As the message above say, the upload was successful, but being an exception, no result is returned with Success etc.

dotps1 commented 6 years ago

the default behavior is to keep default permissions, so, based on the error, could it be the time stamp preservation? I have the behavior of the cmdlets use the same defaults as the WinSCP dll. so PreserveTimestamp defaults to true https://winscp.net/eng/docs/library_transferoptions. Maybe use the New-WinSCPTransferOption and try setting that to false once?

Send-WinSCPItem -WinSCPSession $session -RemotePath $remotePath -LocalPath $localPath -TransferOptions ( New-WinSCPTransferOption -PreserveTimeStamp $false )

See if that helps.

LostLogic commented 6 years ago

Thank you for your reply dotps1. I'll check and see if that resolves my issue. Just have to wait for the accountants to generate some files to be uploaded

LostLogic commented 6 years ago

That seems to have done the trick! Thank you!