General discussion

Locked

FTP with Script

By Lintadsl ·
Dear, Linux guru
I have a data server and backup server running in RedHat 7.3.
Is there any way that I can use a script to FTP a server and upload a file?
I have a data server that I want to backup to a backup server. At this time, I can run tar command to get a tar in data server. Then I want to FTP to backup server to upload tar file.
I have done similar to this in Windows system and I believe Linux is better than Windows. I have tried a few different ways but it did not work.
Any idea would be appreciated.

Thanks in advance.
Lint

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

FTP with Script

by Jezzabel In reply to FTP with Script

Depending on your version of ftp client, you can most definitely script up your transfer. However, consider using ssh/scp instead of ftp, as it's much more secure. With FTP, the password is sent in the clear, as well as the contents of the transfer. I'll prefix the rest of my answer by assuming you're on a secure network. Even then, personally I'd still use scp.

First, create a .netrc file with login and password details, so that you're not prompted for a password. (see man netrc) Thencreate a file with the commands you want to issue, each on one line. Then do "ftp site < script-file".

Collapse -

FTP with Script

by Lintadsl In reply to FTP with Script

Having a problem. Could you help me out writing .netrc file?
I have a ProFTPd server and user name "lintadsl" and password is "123". I am in Data server and trying to FTP to backup server. This would help me a lot. Thanks again.

Collapse -

FTP with Script

by Jezzabel In reply to FTP with Script

Here's an example .netrc file that logs me into ftp.cdrom.com's anon ftp server using a username of ftp and a password of fred@here:

machine ftp.cdrom.com
login ftp
password fred@here

You should be able to create this in your home directory and then type something like:

echo -e 'cd /pub\ndir'|ftp ftp.cdrom.com

and you get back the result of the "dir" command from within the "/pub" directory. Note the "\n" to force a newline. Alternatively, make this script file:

cd /pub
dir

called, say "ftp-script" and then type this:

ftp ftp.cdrom.com < ftp-script

Collapse -

FTP with Script

by Lintadsl In reply to FTP with Script

Great, it works exactly the way I want. Thanks for helping me out. I also have another qeustion. How can I rename a file that add current date to file name? example, test.tar file name would be test03042003.tar once a scrip executed. Any idea?Please contact me at lintadsl@yahoo.com
Thank you.
Sunny

Collapse -

FTP with Script

by Lintadsl In reply to FTP with Script

This question was closed by the author

Back to Linux Forum
5 total posts (Page 1 of 1)  

Operating Systems Forums