Sftp batch file not able to execute


 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Sftp batch file not able to execute
# 1  
Old 07-30-2019
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:

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

Code:
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:

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

Last edited by Scrutinizer; 07-30-2019 at 03:48 AM.. Reason: code tags
# 2  
Old 07-30-2019
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.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-31-2019
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:-
Code:
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG

.... you can then run this:-
Code:
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
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 08-01-2019
Quote:
Originally Posted by rbatte1
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:-
Code:
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG

.... you can then run this:-
Code:
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
Thanks everyone. I was able to run it with -B option which is to execute in a separate file.
These 2 Users Gave Thanks to userguy For This Post:
# 5  
Old 08-01-2019
Moderator's Comments:
Mod Comment moved to Windows subforum


bakunin
# 6  
Old 08-01-2019
Great! Glad we could help.



Kind regards,
Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP batch not renaming file with "put"

I have a .ksh script that creates an sftp batch file and runs it through sftp. It works except for one thing. If I try to "put" to a different name, it doesn't use the specified remote name...it still "puts" the original local name. I've tried both of these, and neither work...it will always... (4 Replies)
Discussion started by: dbiggied
4 Replies

2. UNIX for Advanced & Expert Users

Batch SFTP command Help

I need to run a test SFTP command in a batch mode and what I need to prompt my password after the sftp userid@hostname. I do not have have an ssh key exchanged between my server and the external server. I only have access to it as an sftp server. I must enter my password in my script. How do i... (2 Replies)
Discussion started by: mrn6430
2 Replies

3. Shell Programming and Scripting

How to execute a batch file containing ftp commands??

hi, is there a way i can execute a batch file containing ftp commands like we execute sftp batch file. sftp -b batchfile user@server > output how to create a batch file for ftp executing command and how to run the batch file from a shell script? (2 Replies)
Discussion started by: Little
2 Replies

4. Shell Programming and Scripting

Batch script to run in SFTP

Hello Guys, I am writting a script which is SFTPing from Solaris to Windows. I need to run a Batch script in SFTP session (ongoing) which will map a network drive and then transfer my files. I can run the Batch script via SSH but not via SFTP and this mapping is limited to that SSH... (4 Replies)
Discussion started by: Deei
4 Replies

5. Programming

sftp batch programming

done for this. (4 Replies)
Discussion started by: leganti
4 Replies

6. Shell Programming and Scripting

Batch file for sftp commands

I am trying to automate an sftp command so that it does not stop and ask for the password each time the calling shell script #!/bin/ksh sftp -b tst_1_batchfile.txt GLAXGBUPMPSOUT@204.90.134.116 the batchfile contents : password XXXXXX cd /GLAXGBUPMPSOUT/GSKENT/GLAXGF2FOPFF put... (4 Replies)
Discussion started by: Shrabanti
4 Replies

7. UNIX for Advanced & Expert Users

Sftp in Batch Mode

Hi, I am trying to do sftp a file from one server to another solaris server. Both are sftp enabled. I have generated the rsa key in local server and did a ftped the public key to the remote server and added that in the authorization keys file. Then i try to run the below command using a... (2 Replies)
Discussion started by: sivaemn
2 Replies

8. UNIX for Dummies Questions & Answers

SFTP batch script

Hi, I am running an sftp batch script. sftp -b user@host <<EOF >> /tmp/file.out binary put file.txt bye EOF However, I am getting errors. No such file or directory (user@host). I checked the forums which says I need to access the current process eg for linux I would... (3 Replies)
Discussion started by: Bab00shka
3 Replies

9. Shell Programming and Scripting

help to execute programs in sequence through batch

I need help to create batch file . I want to run some programs in sequence in batch mode . I have one file which contains the name of program and command The test.bat file contain this data stsrun -v devel area1.exp stsrun -v devel prime1.exp stsrun -v devel treat.exp Please help... (1 Reply)
Discussion started by: getdpg
1 Replies

10. UNIX for Dummies Questions & Answers

AT command to batch execute every x hours

I want to schedule a batch job (SQL)to run every 6 hours in Unix and the AT command syntax does not seem to cover this. I have created a file ncd_rpt in the directory report and have given the command in this file. at -f /report/ncd_rpt 1:00 am tomorrow I schedule this by running sh... (1 Reply)
Discussion started by: naveen79
1 Replies
Login or Register to Ask a Question