UNIX - SCP File Transfer


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users UNIX - SCP File Transfer
# 1  
Old 04-08-2008
UNIX - SCP File Transfer

Hi,
How do i know if the files are transferred succesfully when i use SCP to transfer files between 2 servers.

One more is i am trying to send all the files in a single shot by using * to save the connection time. So can i know when the scp breakes in the middle

scp $sourcepath/* user@\$destserver:\$destpath
# 2  
Old 04-08-2008
what do you have so far?

Do you have anything so far other than that line?

You can test for scp's successful completion by looking to see if the exit status is 0 once it finishes. Here's an example:

Code:
#!/bin/bash
echo starting transfer
scp $sourcepath/* user@\$destserver:\$destpath >> /tmp/log.$$
OUT=$?
if [ $OUT = 0 ] ;then
echo transfer successful
else
echo oh no, ftp transfer failed somehow. check log file in tmp for details
fi

Are your scp transfers typically failing? How large are the files you are transferring?

You could also have the script check for files before it transfers, parse the log to see if it needs to retry, email the log files elsewhere, etc.
# 3  
Old 04-08-2008
Please don't perpetrate this silly "test $?" idiom. if already by design examines $?

Code:
if scp $sourcepath/* user@\$destserver:\$destpath >>/tmp/log.$$
then
  echo oh yes >&2
else
  echo "oh no ($?)" >&2
  tail /tmp/log.$$ >&2
fi

What's with the backslashes in \$destserver:\$destpath?

Nothing bash-specific here, by the way, so might as well use good ol' /bin/sh (it's good for you).
# 4  
Old 04-08-2008
Thanks and one more doubt

Thanks a lot for era and tderscheid.

I used back slashes to nullify.

can i delete each file when the copy is done?
If i use SCP by looping i know it can be done but it takes lot of time if i have more files. If i use the * to transfer multiple files it goes in quickly as it dont have to connect every time to the server.
# 5  
Old 04-10-2008
I'm missing some of the bigger-picture elements

Quote:
Originally Posted by vijaykrc

can i delete each file when the copy is done?
If i use SCP by looping i know it can be done but it takes lot of time if i have more files. If i use the * to transfer multiple files it goes in quickly as it dont have to connect every time to the server.
Well, are you generating all the files once, then moving all the files, then deleting all the files, with nothing touching the directory during the transfer? If so, then if your scp /$sourcepath/* has finished with exit code 0, it's reporting success, so the files got to the target machine. As long as nothing has generated more source files, then you could rm /$sourcepath/* and be happy, or depending on your available space, tar them and save them for a week.

How much time are you losing during the connection process? Aren't you ultimately going to automate this and just drink coffee while the move script runs from crontab and then sends you an email of the log when it's done? Is the time you lose actually a critical factor?

If you're having to move, daily, a million tiny files from server A to server B, something else is wrong with that picture. Would server B accept a tar.gz of each group of files you want to send?

I am sure Era can find several other angles to improve this. A little more information about the timeline of file creation might be useful.
# 6  
Old 04-14-2008
Thanks

Thank you for the help...
I may be moving around 5000 files and i cannot tar them... i need to send individually...

I am benefiting around 3 hrs if i send then at a time using the * and if i send then individually its taking that 3-4 hrs more for the 5000 files.
# 7  
Old 04-14-2008
Quote:
Originally Posted by vijaykrc
Thank you for the help...
I may be moving around 5000 files and i cannot tar them... i need to send individually...

I am benefiting around 3 hrs if i send then at a time using the * and if i send then individually its taking that 3-4 hrs more for the 5000 files.
The way I would approach this if the contents of the source directory were likely to change while the copy process is running is to create a shell function to copy one individual file and then to delete it if the copy was successful. I would then start the process by creating a list of all the current files, passing them one by one to the function. This will ensure that only files that were copied correctly get deleted. I know that this will take extra time and resources as each individual file will require a new connection to be set up, but it is, in my opinion the safest way. Of course you will need to set up key authorisation rather than password auth as that would be tedious in the extreme for 5000 files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need some help regarding file transfer between server (sftp/scp)

Hi All, Need some help regarding file transfer between server. Suppose we have system-A and system-B. To transfer file from system-A to system-B we usually share the public keys of system-A to system-B and do scp/sftp to transfer a file. Is it possible that public key of system-B can be... (3 Replies)
Discussion started by: abhi_123
3 Replies

2. Shell Programming and Scripting

Partial File Transfer using scp

I am trying to transfer a zip file of around 30 MB in my automation script using scp from system A to B. When I manually do scp, file is complete transferred but when automation shell script runs it, zip file is not completely transferred. Stack Trace while doing manual : Executing:... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

3. AIX

Problem using scp to transfer a file

I am testing the following command to transfer a file from my server (AIX 5.2) to another server. I was able to generate the keys and sent them the public key. scp -v -P 4030 /home/lawson/.ssh/jimtest.txt someuser@some.ftpsite.net:/Inbound/jimtest.txt > jimtest_out.txt 2>&1 Based on... (3 Replies)
Discussion started by: jyoung
3 Replies

4. UNIX for Advanced & Expert Users

SCP File Transfer

On unix AIX server, when I am trying to transfer file from one directory to another directory on the same server through a program(where i call the script) it gives error "Lost Connection". (5 Replies)
Discussion started by: Pash
5 Replies

5. UNIX for Advanced & Expert Users

SCP File Transfer

I have 3 AIX server namely - Server 1 , Server 2 and Server 3. And have done SCP setup between Server 1 and Server 2 so that i dont have to give password when i transfer file from Server 1 to Server 2 by setting public key between the server. Q1. If the unix password of the target server... (3 Replies)
Discussion started by: Pash
3 Replies

6. UNIX for Advanced & Expert Users

SCP - File transfer message

Whenever I transfer file through SCP between two server it gives below given message.....Is there a way to avoid it.... Target server : newyork $ scp ABC27801.iue newyork:./iABC/x0017801.iue Message ===== This system is for the use of authorized users only. Individuals using this... (1 Reply)
Discussion started by: Pash
1 Replies

7. UNIX for Advanced & Expert Users

scp command for file transfer

I am not able to throw a file from server173 to server067 i.e. wlsuser@server173> scp /tmp/harsha.txt wlsuser@server067:/tmp fails However, I am able to pull a file from server173 onto server067's /tmp dir wlsuser@server067> scp wlsuser@server173:/tmp/harsha.txt /tmp... (2 Replies)
Discussion started by: shifahim
2 Replies

8. UNIX for Dummies Questions & Answers

File transfer using SCP

I have a shell script which uses SCP command to transfer the files from one server to another server. The files are getting transferred successfully, but the problem is the files transferred to the destination server didnot have the permissions as that of the files on the source server. Command... (5 Replies)
Discussion started by: kumarm
5 Replies

9. Shell Programming and Scripting

file transfer using scp..

Hi Frdz I have a problem like. I need to transfer a file from source to destination (different systems with different IPs) using "scp" command and before transfer the file i have to check the file is available in destination or not, if it is there no need to transfer, otherwise we have to... (5 Replies)
Discussion started by: KiranKumarKarre
5 Replies

10. Shell Programming and Scripting

SCP file transfer command on solaris

I need to transfer multiple files using SCP between two solaris machines. Can somebody explain how to achieve that ? (3 Replies)
Discussion started by: parthum
3 Replies
Login or Register to Ask a Question