SFTP files to two servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SFTP files to two servers
# 1  
Old 05-08-2009
SFTP files to two servers

Hi,

I need to write a unix shell script which sends files to a server1 from my server via sftp. Then it needs to again SFTP files from that server1 to another server2. And finally remove the transferred files in the intermediate server1. Please provide me pointers on how to achieve the same. All are unix flavored servers.

Your inputs are greatly appreciated.
Thanks in advance.
# 2  
Old 05-09-2009
I would suggest using scp with password-less SSH setup in preference to sftp for automated transfers.

For the first server you could have a cron job running a script every few minutes or so that simply copys the files to server1 and then moves those files out of the way so they don't get sent again, something like:
Code:
scp -pr * server1:/server1directory
mv * ../donedirectory

Then on Server1 do a cron job calling a script that SCPs one file at a time and if successful deletes the local copy of the file, something like:
Code:
ls -laR > listfile
while read FILE; do
  scp ${FILE} server2:/server2directory 2>&1 > /tmp/scp_log_file
  RESULT=$?
  SCPTEST=`egrep -i "error|fail|denied|illegal|no such|error|unexpected|unknown|too long|lost connection" /tmp/scp_log_file`
  if [ ${RESULT} -eq 0 -a -z "${SCPTEST}" ]; then
    rm ${FILE}
  else
    echo "Error: ${FILE} not sent to server2."
  fi
done < listfile

# 3  
Old 05-10-2009
Thanks Tony.

The requirement is that I should not run a cron job from the server1 (intermediate server). But what I am thinking to do is that I shall login using scp on server2 in my second script from my local server and will fetch the data via ftp from server1 using the commands suggested by you. Please let me know whether this approach will work. Thanks again for your help.
# 4  
Old 05-10-2009
Yes you can run a script on sever2 instead of on server1, ftp would allow you to delete the files from server1 once copied onto server2 whereas scping would require a separate ssh session to delete the files from server1.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Connect direct - SFTP - List of servers that I can connect

Greetings Experts, I am working for a bank client and have a question on connect-direct and SFTP. We are using Linux RedHat servers. We use connect-direct to transfer (NDM) files from one server to another server. At times, we manually transfer the files using SFTP from one server to another... (2 Replies)
Discussion started by: chill3chee
2 Replies

2. UNIX for Advanced & Expert Users

How to setup sftp beteen two servers?

Hi Could you please help me out how to configure between two server I don't have admin idea to setup the Sftp server the requirements is we want to send a file to vendor so we need sftp configuration so that can we can send file through sftp Please let me know what should I ask to vendor... (1 Reply)
Discussion started by: jagu
1 Replies

3. Shell Programming and Scripting

Check files and archive the files using sftp

Hi, I have to check the files in another server using sftp to do that, below is the code i am going with #!/bin/bash export SRC_FOLDER=$1 export ARC_FOLDER=$2 HOST=as07u3456 USER=relfag sftp ${USER}@${HOST} <<EOF cd $SRC_FOLDER/DSCOR ls bye EOF echo "done" whatever the files i... (8 Replies)
Discussion started by: ursrami
8 Replies

4. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

5. Shell Programming and Scripting

Sftp files between servers

I am writing a shell script to copy sybase related .dump files from one to another aix server and visa versa. Please help me do the following The script does the following: - check directory exists - copy dump files - copy is done for multiple database - checks databases, if one... (11 Replies)
Discussion started by: nmm_dba
11 Replies

6. Red Hat

Chroot sftp users, remote sftp login shows wrong timestamp on files

Hello, I have a weird issue, I have RHEL 5.7 running with openssh5.2 where sftpgroup OS group is chroot. I see the difference difference in timestamp on files, when I login via ssh and SFTP, I see four hour difference, is something missing in my configuration. #pwd... (8 Replies)
Discussion started by: bobby320
8 Replies

7. UNIX for Dummies Questions & Answers

Need to calculate sftp time beteen two servers.

Hi, I need to calculate time taken by a 100kb file for sftp between two servers. I am new to unix can some body please tell me how do this. Thanks in advance... Vivek (2 Replies)
Discussion started by: koulvivek
2 Replies

8. UNIX for Dummies Questions & Answers

Unable to scp/sftp between two servers

I have four servers that for all intents and purposes are the same (I have the same profile on all four), North, South, Brooklyn & Queens. I have a script that scp's a file from Queens to brooklyn, and it runs just fine. I tried to replicate the script on South, to transfer a file to North, and... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

9. Shell Programming and Scripting

SFTP Transfer Across Multiple Servers

Hello everyone, Have a question which I'm not entirely sure about, but will ask anyway. We have three servers (A/B/C), 'A' being the local host, 'B' being a SFTP server on the DMZ, and 'C' being the intended remote host. The task is to transfer file/s from server 'A' to server 'C' via server... (0 Replies)
Discussion started by: Cameron
0 Replies

10. Shell Programming and Scripting

need script to connect sftp servers

Dear friends, i need to connect sftp server from my home directory using script . Please can anyone help me on this. (1 Reply)
Discussion started by: kittusri9
1 Replies
Login or Register to Ask a Question