Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sftp in a script

Status
Not open for further replies.

Gloups

IS-IT--Management
Sep 16, 2003
394
FR
Hi list

i'm trying to use sftp in a script but i always get an exit code 0 even if one of the sftp commands fails.

I'd like to stop the job if, for exemple i cant create a remote directory.

Looking to the man pages of sftp i've also tried in batchmode and all failing command should abort the sftp session but it doesn't seem to work.

Any idea to solve my problem ??
 
From
Code:
 man sftp
:
-b batchfile
Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it should be used in conjunction with non-interactive authentication. sftp will abort if any of the following commands fail: get, rm, and lmkdir.

Hope This Help
PH.
 
that's what i also red but i've tried to transfer a non existing file, i had the following message:

File "./toto" not found

but the rest of the commands was executed and exit code always=0
 
If you put non existent file, sftp will not abort.
If you get non existent file, sftp will abort.

Hope This Help
PH.
 
Thank's for your help but regarding to the man pages get and put should work identicaly.

I've aborted my script using mkdir on an existent directory for example but the exit is still 0 the one of the sftp commands seems not to be exported to the shell.

Any solution ?
 
I've also thought to use it but i have to create directories first to store my files. As i know i can't do it with scp

 
With rcp you can use the recursive (-r) flag.
Or you can create remote directories with ssh.

Hope This Help
PH.
 
I can't use that way, the remote directories are realy different.

I think there is a real problem using sftp that's very diffrent of what was written in the man page or may be i should read man pages for donkeys loll
 
Have you tried ssh to use sftp from the remote box ?

Hope This Help
PH.
 
good idea but i can't, thye firewall was only opened that way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top