Help setting $transferOptions.FilePermissions in powershell

Advertisement

notbroken
Joined:
Posts:
2

Help setting $transferOptions.FilePermissions in powershell

Powershell

I need to set the file permissions to Octal 666.

$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

martin
Site Admin
martin avatar
Joined:
Posts:
29,562
Location:
Prague, Czechia

Re: Help setting $transferOptions.FilePermissions in powershell

Use:
$transferOptions.FilePermissions = New-Object WinSCP.FilePermissions
$transferOptions.FilePermissions.Octal = "666"

Reply with quote

notbroken
Joined:
Posts:
2

Re: Help setting $transferOptions.FilePermissions in powershell

martin wrote:

Ue:
$transferOptions.FilePermissions = New-Object WinSCP.FilePermissions
$transferOptions.FilePermissions.Octal = "666"


Worked perfectly. Thank you

Reply with quote

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:
29,562
Location:
Prague, Czechia

Re: Powershell winscp filepermissions

As shown above (https://winscp.net/forum/viewtopic.php?p=54781#54781), this is correct code:

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary 
$transferOptions.FilePermissions = New-Object WinSCP.FilePermissions
$transferOptions.FilePermissions.Octal = "0775"

Alternativelly, 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