PowerShell automation to upload files

Advertisement

TangoPat
Joined:
Posts:
1

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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

Re: PowerShell automation to upload files

The put is correct. Show us how exactly did you try to use it.

This might also help you (with some differences, as you are using PowerShell and not a batch file):
Why are some WinSCP scripting commands specified in a batch file not executed/failing?

Though note that in PowerShell, it's better to use WinSCP .NET assembly:
https://winscp.net/eng/docs/library_powershell

Reply with quote

Advertisement

You can post new topics in this forum