Linux – Automatic FTP file transfer to and from Linux machines

ftplinux

Is it possible to copy files to my Linux machine from another Linux machine automatically with FTP? By "automatically," I mean that FTP would need to handle submitting a login/password combination, as well as copy files, on its own.

Both machines run Red Hat 5.1. I want to get, for example, the file /root/file from the second Linux machine onto my machine and put it under /var/tmp without entering any login/password manually.

I don’t have expect on my machine, and I don't want to use SSH authentication.

If this can't be done automatically by FTP, please suggest an alternate solution, such as a Python script.

Best Answer

You can use the lftp client program and use an FTP script.


lftp supports the ~/.netrc configuration file, in which you can store your credentials:

machine <hostname> login <user> password <password>

You can store a sequence of FTP commands in a file and have lftp execute them, like:

open <hostname>
cd /var/tmp
put /root/file optional_new_filename

The path in cd is on the remote host, the first argument to put is the local file.

Then, just run

lftp -f <filename>
Related Question