LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   File Transfer (https://www.linuxquestions.org/questions/linux-newbie-8/file-transfer-922134/)

richa_s 01-05-2012 12:02 AM

File Transfer
 
Hi,
I'm new to unix, and creating a script to transfer files.
I am able to do so using scp.

Issue is I want to transfer files from a directory located at different unix server and to a directory located at another unix server.

Can any one please help me?

Thanks in advance!

chrism01 01-05-2012 12:13 AM

That's a bit of a short qn, but as per docs http://linux.die.net/man/1/scp
Code:

scp user1@host1:/dir1/file1 user2@host2:/dir2/file2
:)

richa_s 01-05-2012 12:24 AM

Thanks Chris!

Command you specified above is working fine.
But my script is demanding something else.

I'm trying to find all the files in a directory of another server, using below command:

find server:/path/ -type f

After getting the result i will need to place few more filter then i would need to transfer filtered files at a location.

But find cmd prompts with an error: find: stat() error server:/path/: No such file or directory.

chrism01 01-05-2012 07:05 PM

'find' only takes a dir as the search path.
The easiest way to do what you want (assuming I understand requirement), is to login to box1 and do your filtering there, saving file list into a file list (sic), then
Code:

for filename in `cat files.lst`
do
    scp $filename user2@host2:/dir2/$filename
done

NB: untested and assumes no spaces or ctrl chars in filenames.
That should get you started. You may need these links
http://linux.die.net/man/
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

Note also that you'll need any reqd dirs to already exist on the target.

deep27ak 01-06-2012 01:19 AM

I am not very clear about what you are asking.

Please correct me if I am wrong

You are trying to filter some files inside one directory and then copy those files from that particular server to another server?

If this is what you are trying to do then you can simply move all those filtered files into any directory and then copy it to your client machine

Code:

#find / -type f exec cp {} /files/ \;
this will move all your filtered files to /files directory

then

Code:

#scp -rvf /files/* 192.168.0.XX:/path/to/dir/
or I prefer using rsync
Code:

#rsync -avh /files/* 192.168.0.XX:/path/to/dir
if you want the current files to be deleted after copying
Code:

#rsync -avh -delete /files/* 192.168.0.XX:/path/to/dir


All times are GMT -5. The time now is 06:13 AM.