sftp batch file not able to execute

-1

1

I have a windows batch file to connect from Server A (Windows) to Server B (UNIX) via sftp to get a file. The script is as below:

sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg@hostnameB
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG
exit

When I run the script it stops after running the first line i.e sftpg3 -oStrictHostKeyChecking=no...

D:\APPBASE\EAPSG\GEMSSG>sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg@hostnameB
Warning: ignoring unsupported option -o
Warning: ignoring unsupported option -o
Remote system type is POSIX.
sftp>

It didn't execute below lines:

lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG

If I run the command manually one line at a time it works.

Any idea why the script does not run completely?

Thank you.

userguy

Posted 2019-07-30T08:37:06.587

Reputation: 1

1

You have already posted this question on Stack Overflow. And you already got an answer there. So why are you crossposting the question again here? (crossposting is forbidden btw).

– Martin Prikryl – 2019-07-30T08:56:17.857

Answers

1

Batch files do not imitate keyboard input. They start programs and wait for those programs to finish; the whole script is paused until you exit out of sftpg3, and the following lines (lcd, get) will be run as independent commands.

If your sftp client has its own "batch script" option, use that (e.g. OpenSSH has sftp -b, WinSCP has a whole winscp.com meant for scripting).

sftp -b ftpcommands.txt eapsg@hostname

If it does not, you can provide input using redirection, i.e. the < operator:

sftpg3 eapsg@hostname < ftpcommands.txt

Providing commands inline might work using a pipe (though not as convenient as << in Unix shells):

(echo lcd D:\APPBASE\EAPSG\GEMSSG & echo get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG) | sftpg3 host

user1686

Posted 2019-07-30T08:37:06.587

Reputation: 283 655