1847287 Members
2643 Online
110263 Solutions
New Discussion

rcp or ftp script ??

 
SOLVED
Go to solution
someone_4
Honored Contributor

rcp or ftp script ??

I have a file on one box and i want to write a script that will put it in several boxes.
what would be best? to rcp or ftp?
If i rcp how do I rcpt the file for this box to the others? The same with ftp. what do you recommend and why .
thanks..
Richard
7 REPLIES 7
someone_4
Honored Contributor

Re: rcp or ftp script ??

This: with typos
If i rcp how do I rcpt the file for this box to the others? The same with ftp.
should be : without typos
If I rcp how do I rcp the file form this box to the others? The same with ftp.

Thanks
A. Clay Stephenson
Acclaimed Contributor

Re: rcp or ftp script ??

As long as your within the UNIX world and not having to send the file to those pesky PC's I would use rcp simply because it is much easier to script and you can also specify permissions
wvia -p argument.

My 2 cents, Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: rcp or ftp script ??

Ok Richard, now that I see your full question:

Something like this:
FILES="/tmp/file1 /home/richard/file2"
REMOTES="huey louie dewey"
for FILE in ${FILES}
do
for REMOTE in ${REMOTES}
do
rcp -p ${FILE} ${REMOTE}:${FILE}
done
done

That will do it. You will need to set up host.equiv's and .rhosts but that's it.

Clay
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: rcp or ftp script ??

Hi Richard:

'rcp' has an advantage over 'ftp' that can be very useful, namely the timestamps and permissions of files can be maintained by using the '-p' option. With 'ftp' this only occurs if an existing file of the same name exists (empty or not).

'rcp' is a remote 'cp' and so has the recursive copy features which can be harder to handle in scripted ftp sessions.

However, 'ftp' is genearally implemented on all operating systems. 'rcp' is a unix-to-unix tool.

Therefore, the choice is really yours, depending upon the task, its complexity, and the availability of 'rcp' on the sending and receiving ends.

...JRF...
Thierry Poels_1
Honored Contributor

Re: rcp or ftp script ??

Hi Richard,
one more option is rdist.
Have a look in the man pages, it's quite similar to rcp.
good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
someone_4
Honored Contributor

Re: rcp or ftp script ??

Thanks everyone .. one quick question A.Clay
the script you gave me worked fine.
But if I want to put one file form one dir to a differnt dir in the other box how would i write that?
A. Clay Stephenson
Acclaimed Contributor

Re: rcp or ftp script ??

Hi Richard:
It's easy. The answer is just like you would with plain old cp.

e.g. rcp -p /tmp/file1 remote_host:/tmp2/file1
or
rcp -p /tmp/file1 remote_host:/tmp2/file2

BTW you can reverse the sense of the arguments
and copy from the remote host, if you wish.

e.g. rcp -p remote_host:/tmp2/file1 /tmp/file1

Finally if you want to specify full paths on the source like my example and different destination directories then you should use 'basename' and 'dirname'. Man basename and dirname for details.

Clay
If it ain't broke, I can fix that.