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

onefiscus

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"
onefiscus

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()
}