GeeksWeb

Auto login using ftp command in Linux

In Linux sftp allows to specify username along with the URL like this:


$ sftp username@host

However, ftp does not support such a feature. This makes it hard since one needs to remember bunch of usernames for each server. And some are so unintuitive to memorize. If a secure machine is used, not a 24/7 the Internet connected server, still there is a way to workaround the problem using switch -n.
What has to be done is to edit/create .netrc file of/to the user home directory and add an entry like this:


machine hostaddress
   login username

Then save the file and run ftp command like this:


$ ftp host

After that the ftp command picks up the username matches the host address from .netrc file and no longer requires for username, just prompts for password.
It is also possible add password to .netrc file like this:


machine hostaddress
   login username
   password password

I highly recommend against of it. It is unsecure and if the system gets hack, all the credentials will be available to the crackers.
.netrc supports multiple entries, similar to following:


machine hostaddress1
   login username1

machine hostaddress2
   login username2