Search code examples
sftpwinscp

How to generate transfer code/script in WinSCP


I have the below command I started writing to copy a file from a local box to the remote directory. I am very new to this and confused by the documentation somewhat. Can I use the "Your Command 1 and 2" params at the end to do like "c:\somefile.txt" "\in\"?

I want to do this without PowerShell, or script. Just raw command line and no additional files to import in command line args. My goal is to set up a Windows Task Scheduler job and has it run this single command.

C:\Program Files (x86)\WinSCP\WinSCP.exe /log="C:\writable\path\to\log\WinSCP.log" /ini=nul /command "open sftp://myusername@myftpsite.com/ -hostkey=""ssh-rsa 2048 wbb2bQRmDJqkaLbuYKsnGdxQ40mIIedeXChRsAYC3ig="" -privatekey=""C:\Users\my.user\Documents\SSHPrivateKey.ppk""" "Your command 1" "Your command 2" "exit"

I see some examples here… https://winscp.net/eng/docs/commandline#scripting

Can't find auto-generate code function in transfer settings for full script code...

enter image description here


Solution

  • The command to upload a file is put. You can place it instead of the "Your command 1" "Your command 2" placeholders like this:

    "C:\...\WinSCP.exe" ... /command "open ..." "put C:\local\file.zip /remote/" "exit"
    

    WinSCP GUI can generate a complete command-line including the put command for you:

    • Initiate a transfer in the GUI. You have to do it a way that pops up the Transfer Options dialog. The dialog does not typically show for drag&drop transfers (unless you opt for it in preferences). Instead, use the main menu or a file(s) context menu, a toolbar button or a keyboard shortcut.
    • On the dialog, drop down the menu at the Transfer Settings button.
    • Select the Generate Code command.
    • Generate Transfer Code Dialog opens.
    • On the Generate Transfer Code Dialog, select the Command-line format.