I have a batch file for moving file from my local PC to server through SFTP. I have PuTTY installed in my system and the batch file code follows.
cd C:\Program Files (x86)\PuTTY psftp open <IP> <user> <PW> cd /home/irisuser/iris/integration/dls_dlsblr_dlschnn_in_msg/in lcd d:\ put log.sh bye
The above code perfectly works when I type it in command prompt. But when I double click the
.bat file and run it, it's not running and asking for username and password to be entered. My aim was to automate the whole thing and I need to run it by simply clicking the
.bat file. But am not able to achieve it. Any ideas or snippets will help me.
This question is tagged with
~ Asked on 2013-05-08 11:06:15
You need to store the psftp script (lines from
bye) into a separate file and pass that to
cd "C:\Program Files (x86)\PuTTY" psftp -b "C:\path\to\script\script.txt"
EDIT: For username+password: As you cannot use
psftp commands in a batch file, for the same reason, you cannot specify the username and the password as
psftp commands. These are inputs to the
open command. While you can specify the username with the
open command (
open <user>@<IP>), you cannot specify the password this way. This can be done on a
psftp command line only. Then it's probably cleaner to do all on the command-line:
cd "C:\Program Files (x86)\PuTTY" psftp -b script.txt <user>@<IP> -pw <PW>
And remove the
<PW> lines from your
What you are doing atm is that you run
psftp without any parameter or commands. Once you exit it (like by typing
bye), your batch file continues trying to run
open command (and others), what Windows shell obviously does not understand.
If you really want to keep everything in one file (the batch file), you can write commands to psftp standard input, like:
( echo cd ... echo lcd ... echo put log.sh ) | psftp -b script.txt <user>@<IP> -pw <PW>
~ Answered on 2013-05-08 12:16:47
set DSKTOPDIR="D:\test" set IPADDRESS="18.104.22.168" >%DSKTOPDIR%\script.ftp ECHO cd %PAY_REP% >>%DSKTOPDIR%\script.ftp ECHO mget *.report >>%DSKTOPDIR%\script.ftp ECHO bye :: run PSFTP Commands psftp <domain>@%IPADDRESS% -b %DSKTOPDIR%\script.ftp
Set values using set commands before above lines.
I believe this helps you.
Referre psfpt setup for below link https://www.ssh.com/ssh/putty/putty-manuals/0.68/Chapter6.html
~ Answered on 2019-02-16 12:44:37