Automatic FTP file transfer to and from Linux machines

3

1

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.

diana

Posted 2011-11-14T04:50:23.553

Reputation: 61

Use key based SSH authentication and SCP.

– Daniel Beck – 2011-11-14T04:52:21.133

sorry I dont want to use SSH authentication – diana – 2011-11-14T04:58:20.023

Answers

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

Posted 2011-11-14T04:50:23.553

Reputation: 98 421

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

Posted 2011-11-14T04:50:23.553

Reputation: 4 039

please give me example – diana – 2011-11-14T05:00:07.917

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 – 2011-11-14T05:01:44.030

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 – 2011-11-14T05:04:12.467

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 – 2011-11-14T05:09:16.403

your example not good because need the password entering, the target is to login & password auto – diana – 2011-11-14T05:47:11.557

Please re-read my initial post. – Garrett – 2011-11-14T05:48:33.703