Automation

 View Only
  • 1.  scp with powershell - set file permissions

    Posted Feb 13, 2019 12:00 PM

    Hello guys,

    I have a script for Putty who sending everyday some report from a Win directory to Linux server with scp

    Not sure if I can manage directly with this script, I would like to set some permissions on files before I sent,

    The Linux directory have some restrictions, directory 775 (drwxrwxr-x)  but file became from Win server with  (640 -rw-r-----)

    This is script:

    $file = Get-ChildItem -Path C:\temp\smart_backup\*.csv |

      Sort-Object -Property LastWriteTime -Descending |

      select -First 1 -ExpandProperty FullName

    $sProc = @{

      FilePath = 'C:\Program Files (x86)\PuTTY\pscp.exe'

      ArgumentList = "-scp -pw ******* $file smart@1.1.1.1:/data/smart/invoicing/"

    }

    Start-Process @sProc

    Any suggestion or I should find a way in Linux server directly?

    Thanks



  • 2.  RE: scp with powershell - set file permissions

    Posted Feb 13, 2019 12:11 PM

    I owuld encourage you to have a go with the Posh-Ssh module.
    Makes SSH a lot easier.

    Changing permissions can be done like this

    $esxName = 'myesx.my.domain'

    $cred = Get-Credential -Message 'Enter credentials'

    $cmdsub = @'

    chmod 644 /tmp/test.file

    '@


    $esx = Get-VMHost -Name $esxName

    $session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey

    $result = Invoke-SSHCommand -SSHSession $session -Command $cmdSub

    Remove-SSHSession -SSHSession $session | Out-Null