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.

2

2 Answers 2

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>
0
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.

6
  • please give me example
    – diana
    Nov 14, 2011 at 5:00
  • An example would largely depend on how you're trying to do the transfer and what you are doing. Your post didn't provide enough of those details for me to give a detailed example in return.
    – Garrett
    Nov 14, 2011 at 5:01
  • all I want is to get the /root/file from linux2 machine and copy this file to my linux1 under /var/tmp without login=root/password=pass123
    – diana
    Nov 14, 2011 at 5:04
  • Setup SSH key auth and use rsync -e ssh in a simple Bash script to copy the file. E.g. rsync -avH -e ssh root@linux2:/root/file /var/tmp/
    – Garrett
    Nov 14, 2011 at 5:09
  • your example not good because need the password entering, the target is to login & password auto
    – diana
    Nov 14, 2011 at 5:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .