Friday, July 15, 2011

Automating Remote File Copy

When you need to move files around inside a secure environment, rcp and ftp scripts can be a real time saver.

rcp

The easiest way to copy a file from any machine to a destination host without using password is to use the .rhosts file. This file should reside in a user's home directory. For example, for user "foo" on host "dest", this file will contain this line:


+ foo


Now you can remote copy files from anywhere to host "dest" without typing a password:

rcp file foo@dest:/home/foo/.

Scripting ftp

The trick to script ftp command is to turn off the interactive mode by using the "-n" option. This allows you to put password in the script. Here is an example to ftp a file from foo's home directory:


#!/bin/sh
ftp -n dest  << whatever
user foo foopass
bin
get file
bye


These two little commands can do wonders in a heterogeneous but secure environment with mixed Linux/Unix/Windows boxes. Use them to your heart's content.

No comments:

Post a Comment