1

I have created a bat file to transfer files from a pc to server Everything works fine when a enter command manually but I doo not know how to convert in a script as it will stop after enter password request

cd c:\users\user\documents\transfer

sftp [email protected]

put *.txt 

The problem is that when the system requests a password, I enter the password but it will stop and I will need to write down the rest of the script

Is there any way to make the script to continue after entering the password?

1 Answer 1

0

The password is not the problem; the problem is that scripts do not imitate keyboard input. They run commands in series, and as far as the script is concerned, the sftp command is still running – it's showing its own input prompt, but the script cannot do anything with that. Only when 'sftp' exits, the put command will be executed within the main Cmd.exe interpreter, not within sftp.

  • Use the sftp -b option to pass a separate script to the 'sftp' program.

    cd/d c:\users\user\documents\transfer
    sftp -b c:\whatever\putall.txt [email protected]
    
  • Use the scp command. (In latest OpenSSH versions it is even SFTP-based.)

    cd/d c:\users\user\documents\transfer
    scp *.txt [email protected]:
    
  • Pipe the commands as explicit input to sftp (I am not sure whether this works on Windows).

    cd/d c:\users\user\documents\transfer
    echo put *.txt | sftp [email protected]
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .