Automatic login with ftp

FTP clients on unix look for .netrc file in user's home directory for auto-login process. You'd normally want to save the login information of servers that you frequently login to in this file. The permissions on this file must be read only for the owner otherwise ftp clients will ignore the file and show a warning message. The format of the entries in .netrc file is as shown below.

machine name_of_the_host login username password your_password
default login anonymous password your@email.address

default matches any machine name. There can be only one default entry. This should be the last line in your .netrc file. Entries after this line are ignored.

Use this command to change the permissions to 600 (read_write for the owner).

chmod 600 ~/.netrc

If the remote server requires an account password (different from login-password), you can add this info in the file with the following token.

account account_password

The automatic login process sends this password to the remote host.

You can also create macros in .netrc file. The token to define a macro is of the form

macdef name_of_the_macro

This line follows the set of ftp commands to be executed. If you want to execute certain set of commands on automatic login, put those commands in a macro called 'init'.

How to execute macros ?

Macros can be executed in two ways.

  1. In an ftp session
    ftp>$ name_of_the_macro
  2. From the command line
    mukul@zero >> echo "\$ name_of_the_macro" | ftp remote_host

Warning : If somebody can read your .netrc file, he can easily get your login info on the remote hosts that you login to.

Back to Linux Tips

More Info

Don't forget to see our Tools' page and linux resources page
For Linux commands see - Useful Linux Tips

gnuServices interests

gnuServices tools...

Report Generation

Open Source

Report Generation is an integral part of enterprise application. We write Shell scripts for automation and Perl scripts for Report Generation of various kinds. More…

Knowledge Base

Website Applications

With Perl, PHP - We use CSS layouts which is the latest trends in web-designing. This has many advantages over the old-school web-design practices. If you would like to learn more about what it is, please visit www.zeldman.com. More…