Home > Documentation > FTP Server > How to automate ftp login for a shell script

How to automate ftp login for a shell script

Posted by peter on November 18, 2011

Sometimes you need a scripts to automatically ftp to a server that requires a user name and password. Here is how to do it.

Create a file called ".netrc" in your home directory (the user who will run the script). Put the following in the file:

machine ftp.serveryouneedtoconnectto.com login yourloginname password yourpassword

Edit the above to suit.

Make sure permissions on the .netrc are correct for the user and that the user has a valid logon on the remote ftp server.

NB Make sure .netrc file is rw for the owner and no access for everyone else. This is for security reasons. To change permissions type the following:

chmod 600 ~/.netrc

 

Comments:

Leave a Reply



(Your email will not be publicly displayed.)

Please type the letters and numbers shown in the image.Captcha CodeClick the image to see another captcha.