Categories:- Unix Commands

Set FTP Autologin with .netrc file in linux

There are some scenario where we do not want to specify ftp user name and password on the ftp command line. So to automatically supply ftp username and password to the ftp client, create a file .netrc in user's home direcrory which contains the information regarding the ftp server name, ftp user & password.


We can also use .netrc file in a shell script where we will use ftp client to transfer files to remote ftp server.


Below are the steps to enable FTP autologin with .netrc file .

Step:1 Create a .netrc file in user's home directory

# vi ~/.netrc

machine <FTP-Server-Name> login <User-Name> password <XXXXX>

Example :

machine  login ftp-user password xyz@abc123

Save & Exit the file.


Note: We can add multiple machines ,Just one line per machine in the .netrc file.


Step:2 Set permissions so that Owner can only read the file

# chmod 0600 ~/.netrc

Step:3 Now Try to connect Your ftp server

# ftp < FTP-Server-Name>

Now above command will connect to your ftp server automatically, whereas ftp user name and password is picked up from .netrc file

comments powered by Disqus