Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

AJDValien

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!
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. :(
Southbay

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.
AJDValien

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)