There are some scenarios 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 the user’s home directory 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 the .netrc file.
Create a .netrc file in user’s home directory
# vi ~/.netrc machine [FTP-Server-Name] login [User-Name] password [XXXXX]
machine ftp.nstpmail.com login ftp-user password xyz@abc123
Save & Exit the file.
Set permissions of the .netrc file so that only owner can readt the file:
# chmod 0600 ~/.netrc
Try Connecting FTP server
Npw you can try connecting your FTP server as shoen below:
# 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