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.
- In an ftp session
ftp>$ name_of_the_macro - 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.