Help with PowerShell script to copy file from Windows folder to Linux Folder

Advertisement

g0nz0uk
Joined:
Posts:
7

Help with PowerShell script to copy file from Windows folder to Linux Folder

Hello,

I'm currently using WinSCP (GUI) to manually copy a single .csv file from a Windows directory to a Linux directory. I now need to set this up as a schedule in Windows Scheduler as it needs to run every 10mins.

I used the Generate Session code for PowerShell but it only creates part of it as seen here:
& "C:\Program Files (x86)\WinSCP\WinSCP.com" `
  /log="C:\Program Files (x86)\WinSCP\WinSCP.log" /ini=nul `
  /command `
    "open sftp://copyuser1:password%21@192.168.14.13/ -hostkey=`"`"ssh-ed25519 255 A1i189222n9cijblOCqz/Yk9FUXo/wstTNqyhp9VE=`"`"" `
    "Your command 1" `
    "Your command 2" `
    "exit"
 
$winscpResult = $LastExitCode
if ($winscpResult -eq 0)
{
  Write-Host "Success"
}
else
{
  Write-Host "Error"
}
 
exit $winscpResult
I want it to copy from this source to the destination.

Source Windows location = C:\Reports\myfile.csv

Destination Linux Location = usr\share\csv

Can someone help me fill in the gaps/commands?

Reply with quote

Advertisement

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

Re: Help with PowerShell script to copy file from Windows folder to Linux Folder

    "put C:\Reports\myfile.csv /usr/share/csv" `
or
    "put C:\Reports\myfile.csv /usr/share/csv/" `
(It's not clear if the csv is a file or folder).
See https://winscp.net/eng/docs/scriptcommand_put

Though note that the code generation function can generate even a full upload code, if you use it correctly. See https://winscp.net/eng/docs/guide_automation#generating

Reply with quote

Rohan
Guest

Hi, if that is worked
Where to put "put C:\Reports\myfile.csv /usr/share/csv" ^ this line? After open sftp line?
Kindly help

Reply with quote

martin
Site Admin
martin avatar

@Rohan: Yes, in place of the "Your command 1" ` and "Your command 2" ` lines. Note that there was a typo in my answer. The lines should end with `, not ^ (I've corrected my previous post).

Reply with quote

Advertisement

You can post new topics in this forum