I have a bat file I call everynight to transfer some files.
I want to put a file from my computer to my remote server. I have installed PSFTP and I don't know how to use it in batch way.
I put this :
CD /D C:\Users\Vincent\Desktop
psftp user@99.99.99.99 -pw password -P port
put file.csv /remote/folder/file.csvBut when I call my BAT file, it stucks on :
psftp > _How can I use it as automate mode ?
1 Answer
First of all, lets diagnose why it does not work.
- Batch file starts. Probably in C:\users\vincent\
- Working directory gets changed by the first command. this command finishes and the processing moves on to the next command.
psftp user@99.99.99.99 -pw password -P portget started. It is running and waiting for user input.- The next command does not get reached until the previous one ends. If you are a quick reader then you can type
quitand see a the error message thatput is not a recognised internal or external commandbefore the windows closes.
Ok, so we now found that we are issueing a third command rather than input for psftp. The question now is how you can issue orders to the running psftp program.
Chapter 6, section 6.1.5 of psftp meanion the -b option. Quoting that:
In normal operation, PSFTP is an interactive program which displays a command line and accepts commands from the keyboard. If you need to do automated tasks with PSFTP, you would probably prefer to specify a set of commands in advance and have them executed automatically. The -b option allows you to do this. You use it with a file name containing batch commands. For example, you might create a file called myscript.scr containing lines like this:
It then lists an example. In your case the file probably should contain this:
put file.csv /remote/folder/file.csv
quit