Help with SFTP script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Help with SFTP script

Shell Programming and Scripting


Tags
sftp put upload file files

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-21-2013
raghunsi raghunsi is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 16 April 2014, 2:32 AM EDT
Location: bangalore
Posts: 107
Thanks: 3
Thanked 0 Times in 0 Posts
Help with SFTP script

Hi All,

I'm in need of script which picks multiple files from one server and do sftp to multiple servers. Any help would be much appreciated.
Sponsored Links
    #2  
Old 07-21-2013
spacebar's Avatar
spacebar spacebar is offline
Registered User
 
Join Date: Oct 2009
Last Activity: 2 June 2014, 3:23 PM EDT
Location: spaceBAR Central
Posts: 440
Thanks: 0
Thanked 70 Times in 70 Posts
This is a simple example example of putting a file with sftp, You can create a similar script to get file(s):

Code:
#!/usr/bin/ksh
# test_sftp.sh
sftp -b /dev/stdin -v -o BatchMode=yes -o IdentityFile=/export/home/user/.ssh/id_rsa -o Port=22 user@host <<ENDSFTP
cd /home/user/test
put /export/home/user/test/test.txt test.txt.xferring
rename test.txt.xferring test.txt
quit
ENDSFTP
rc=$?
if [[ $rc != 0 ]]    then
    print "Error occured...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
else
 print "Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
fi


Last edited by Scott; 07-21-2013 at 04:49 PM.. Reason: Removed font tag again...
Sponsored Links
    #3  
Old 07-21-2013
gacanepa gacanepa is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 26 July 2014, 8:32 PM EDT
Location: Villa Mercedes, San Luis, Argentina
Posts: 164
Thanks: 21
Thanked 24 Times in 21 Posts
Quote:
Originally Posted by spacebar View Post
This is a simple example example of putting a file with sftp, You can create a similar script to get file(s):

Code:
#!/usr/bin/ksh
# test_sftp.sh
sftp -b /dev/stdin -v -o BatchMode=yes -o IdentityFile=/export/home/user/.ssh/id_rsa -o Port=22 user@host <<ENDSFTP
cd /home/user/test
put /export/home/user/test/test.txt test.txt.xferring
rename test.txt.xferring test.txt
quit
ENDSFTP
rc=$?
if [[ $rc != 0 ]]    then
    print "Error occured...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
else
 print "Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
fi

raghunsi,
This is an outstanding example that uploads a file to a specific host. Do you know how to tweak it in order to do the same thing for multiple servers? (For example, with a while loop). Let us know if you need further help and we'll be more than glad to lend a hand.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how i can use sftp in script gagandeep Shell Programming and Scripting 2 08-31-2012 12:05 PM
sftp script rahulsxn660 Shell Programming and Scripting 1 11-01-2011 11:17 AM
SFTP-how to log individual sftp command error while executing shell script noobrobot Shell Programming and Scripting 1 10-09-2011 07:17 PM
Script for sftp pepeli30 UNIX for Dummies Questions & Answers 7 01-08-2010 07:30 AM
SFTP script HROMERO UNIX for Dummies Questions & Answers 0 10-19-2005 04:50 PM



All times are GMT -4. The time now is 03:47 PM.