transferOptions.FilePermissions question.

Advertisement

AJDValien
Joined:
Posts:
3

transferOptions.FilePermissions question.

Hi all,

Not sure if this is the right forum or not. Been automating WinSCP using some Powershell scripts. But when I do an upload I get this error:

PS R:\PowerShellScripts> .\SFTPToPDCs.ps1
Beginning FTP Upload.
Upload of file '1208E.pjb' was successful, but error occurred while setting the
permissions and/or timestamp. If the problem persists, turn on 'Ignore permissio
n errors' option.
PS R:\PowerShellScripts> .\SFTPToPDCs.ps1

So looking around the documentation I stumbled on this:

https://winscp.net/eng/docs/library_filepermissions
and this to remove it via the GUI or command line - https://winscp.net/eng/docs/ui_transfer_custom#upload

So how would I implement this in my script? I looked at the PS examples but no go.

Would this work? (text in red)

$transferOptions.FilePermissions = $Null

The idea is to keep the permissions the same when I upload the files.

# Connect
      Write-Host "Beginning FTP Upload."
        $session.Open($sessionOptions)
 
        # Upload files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
   $transferOptions.FilePermissions = $Null
      
      $transferResult = $session.PutFiles("R:\RESOURCES\Data\*", "/users/xfer/", $FALSE, $transferOptions)

Reply with quote

Advertisement

Southbay
Joined:
Posts:
1
Location:
USA

Re: transferOptions.FilePermissions question.

I'm having the exact same problem. I'm using WS_FTP as the destination server and I can get a single file uploaded but then it throws the exception. I attempted your TransferOptions.FilePermissions=$Null idea but no go for me. I really wish I could have gotten this to work, put a bit of time into this powershell script which wraps winscp.

Reply with quote

AJDValien

Wow, surprised no one else has weighed in on this. For now I have to manually FTP (using FileZilla) instead of WinSCP since I can't override (or figure out the override) on the permissions to automate it. :(

Reply with quote

AJDValien
Joined:
Posts:
3

Just now getting back to this. Was able to test this tonight and PowerShell does not recognize the null option and throws this exception:

The term 'null' is not recognized as the name of a cmdlet, function, script file
, or operable program. Check the spelling of the name, or if a path was included
, verify that the path is correct and try again.

So back to the drawing board...

This is what I had in my PS script:

        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
      $transferOptions.FilePermissions = null
      $transferOptions.PreserveTimestamp = false

Edit: Got it!

Had to use this for PowerShell to pick it up:

$transferOptions.FilePermissions = $null
$transferOptions.PreserveTimestamp = $false

Worked like a charm!

Reply with quote

Advertisement

You can post new topics in this forum