Using PSFTP to send file to remote server

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.csv

But 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.

  1. Batch file starts. Probably in C:\users\vincent\
  2. Working directory gets changed by the first command. this command finishes and the processing moves on to the next command.
  3. psftp user@99.99.99.99 -pw password -P port get started. It is running and waiting for user input.
  4. The next command does not get reached until the previous one ends. If you are a quick reader then you can type quit and see a the error message that put is not a recognised internal or external command before 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like