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

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.