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

TangoPat

PowerShell automation to upload files

I am working on a script to automate upload of 2 files daily.
The first part of the script works I am able to connect to the site. But it get stuck after that where I have to upload files. What command should I use for "Your command 1" ` + "Your command 2" `. I have tried the put command it did not work.
Below is the code
& "C:\Program Files (x86)\WinSCP\WinSCP.com" `
  /log="C:\writable\path\to\log\WinSCP.log" /ini=nul `
  /command `
    "open sftp://B*******_sftpcommon@banklabssftp.com/ -hostkey=`"`"ssh-ed25519 255 fEbePT1DJOz+hH8KMW3**************`"`" -privatekey=`"`"C:\SFTP key\B*******_sftpcommon_id_rsa.ppk`"`"" `
    "Your command 1" `
    "Your command 2" `
 
$winscpResult = $LastExitCode
if ($winscpResult -eq 0)
{
  Write-Host "Success"
}
else
{
  Write-Host "Error"
}
 
exit $winscpResult