windowsbatch-filesftpputtypsftp

Can I pass the content of the batch file directly as argument instead of saving it in a batch file and passing the file itself?


Can I pass the content of the batch file directly as argument instead of saving it in a batch file and passing the file itself?
My question is the following, instead of using this:

psftp.exe user_name@host_domain -pw user_pw -b example_batch_file.bat

example_batch_file.bat content:

get filename.csv

I would like to use something like this (in one go, not manually opening the console and doing it one after another, its for automatisation purpose):

psftp.exe user_name@host_domain -pw user_pw -get filename.csv

Solution

  • The psftp can read the commands from the standard input.

    So you can do:

    (
      echo get filename.csv
      echo other command
    ) | psftp.exe user_name@host_domain -pw user_pw
    

    If you really need one-liner, then:

    ( echo get filename.csv && echo other command ) | psftp.exe user_name@host_domain -pw user_pw
    

    Though note that psftp also reads answers to its prompts from the standard input. So you will want to add -batch switch to disable all prompts and make psftp automatically fail instead.