Help setting $transferOptions.FilePermissions in PowerShell

Advertisement

notbroken
Joined:
Posts:
2

Help setting $transferOptions.FilePermissions in PowerShell

I need to set the file permissions to octal 666 in PowerShell.
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.FilePermissions = ?
I am new to PowerShell and am trying to work through this "Create new instance of FilePermissions and set FilePermissions.Octal to a value of the switch."

Any help/guidance would be appreciated

Reply with quote

Advertisement

rams
Guest

Powershell winscp filepermissions

I have to use the following:
Write-Host "transferOptions.FilePermissions Object Creation ..."
            
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary 
$transferOptions.Octal = New-Object WinSCP.FilePermissions
$transferOptions.Octal = "0775"
Why?
Reason: $transferOptions.FilePermissions is NOT valid property error?
Write-Host "Uploading $line ..."
 
$transferResult = $session.PutFiles($line, $remotePath, $false, $transferOptions).Check()
Please help?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,005
Location:
Prague, Czechia

Re: Powershell winscp filepermissions

As shown above, this is the correct code:
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary 
$transferOptions.FilePermissions = New-Object WinSCP.FilePermissions
$transferOptions.FilePermissions.Octal = "0775"

Alternatively, like this:
$transferOptions = New-Object WinSCP.TransferOptions -Property @{
    TransferMode = [WinSCP.TransferMode]::Binary 
    FilePermissions = New-Object WinSCP.FilePermissions -Property @{ Octal = "0775" }
}

You can have the latter code generated by WinSCP GUI:
https://winscp.net/eng/docs/ui_generateurl#code

Reply with quote

Advertisement

You can post new topics in this forum