Sftp batch file not able to execute

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.

The sftp3g command seems to wait for input. Were it on a *nix system, I'd propose a "here document" containing the lines for sftpg3. On MS systems, I'm afraid I can't help.

1 Like

Does you client support the -b flag for sftp? That would allow you to write the commands you want in a separate file and refer to the file in your sftp command.
At the moment, the sftp command starts and will wait for input. If it were ever complete (e.g. you press CNTL-D) then the script will continue with the next command, in your case lcd D:\APPBASE\EAPSG\GEMSSG which will likely generate an error.

If you write this in a file my_sftp_commands:-

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

.... you can then run this:-

sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA -b my_sftp_commands ftpeapsg@hostnameB

This does depend if your sftp3g client supports it though. What is the OS and emulator (if there is one, e.g. Cygwin)

I hope that this helps,
Robin

1 Like

Thanks everyone. I was able to run it with -B option which is to execute in a separate file.

2 Likes

bakunin

Great! Glad we could help.

Kind regards,
Robin

1 Like