Monday, November 06, 2006

ftp scripts without passwords

As old as ftp is, i'm sure its still a very common method of file transfer in most interfaces.

Here's how to write a simple ftp script on unix or windows without having to worry about those passwords.

Using EOF

Probably the most common is to use the EOF (end of file) method. Its important to know that there cannot be any spaces in front of the last 'EOF' line.

ftp -nv hostname << EOF
cd directory
mput filename.*

Using .netrc

The other method of saving passwords for multiple scripts is to use a .netrc file which can be created in the user's home directory

$ cd $HOME
$ vi .netrc

add the following line into the file

machine login password

$ chmod 500 .netrc

You should be able to ftp without prompts. to test, just type

$ ftp

you should be logged in. the downside is that this forces you to log in as that specific user. However lets face it, if you're still using ftp to move stuff around, this shouldn't bother you one bit.

Personally, I would recommend that sftp or scp be used instead. pub key management is so much more convienient.

No comments:

Splitting the home network

Who wouldn't want to separate the traffic at home for security reasons. The more common ones include wireless guest and wireless users. ...