3

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.

Pops
  • 8,623
diana
  • 61

2 Answers2

5

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>
Daniel Beck
  • 111,893
0

You can always store the credentials in a file and pass them as an argument to the script which is calling the FTP command, however I would recommend using SFTP (FTP over SSH) instead with key-based authentication as per my reply to another post. Key-based authentication is more secure and your data & login channels will be encrypted.

Garrett
  • 4,217
  • 1
  • 24
  • 33