Set file permissions while doing powershell file transfer

Advertisement

onefiscus
Joined:
Posts:
2

Set file permissions while doing powershell file transfer

I have this simple script that transfers a few files, the problem is that the files transfer with 0660 permissions and I need them to be 0644, how can I set this during the transfer process?

Add-Type -Path "D:\FTPScripts\WinSCPnet.dll"

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "example.com"
        UserName = "user"
        Password = "mypassword"
        SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}

$session = New-Object WinSCP.Session

    $Path = "Uploads/"

try
{
    $session.Open($sessionOptions)

        $session.PutFiles("D:\UserRoles\*UserList*", "$Path/reconUserPath/", $False, $transferOptions)
      $session.PutFiles("D:\UserRoles\*UserRole*", "$Path/reconURolePath/", $False, $transferOptions)
      $session.PutFiles("D:\UserRoles\*ROLES*", "$Path/reconRolePath/", $False, $transferOptions)   
}
finally
{
    $session.Dispose()
}

Reply with quote

Advertisement

onefiscus
Joined:
Posts:
2

Re: Set file permissions while doing powershell file transfer

onefiscus wrote:

I have this simple script that transfers a few files, the problem is that the files transfer with 0660 permissions and I need them to be 0644, how can I set this during the transfer process?

Add-Type -Path "D:\FTPScripts\WinSCPnet.dll"

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "example.com"
        UserName = "user"
        Password = "mypassword"
        SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}

$session = New-Object WinSCP.Session

    $Path = "Uploads/"

try
{
    $session.Open($sessionOptions)

        $session.PutFiles("D:\UserRoles\*UserList*", "$Path/reconUserPath/", $False, $transferOptions)
      $session.PutFiles("D:\UserRoles\*UserRole*", "$Path/reconURolePath/", $False, $transferOptions)
      $session.PutFiles("D:\UserRoles\*ROLES*", "$Path/reconRolePath/", $False, $transferOptions)   
}
finally
{
    $session.Dispose()
}
I figured it out:
$transferOptions.FilePermissions = New-Object WinSCP.FilePermissions
$transferOptions.FilePermissions.Octal = "644"

Reply with quote

Advertisement

You can post new topics in this forum