Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to so the same thing like in SSH where you can save the server in the config file. I would also like to save my username and password, so that it is not prompted each time I connect. I use the ftp command,

share|improve this question
    
Create ~/.netrc file and check below answer for the format. –  Nikhil Mulley Jan 6 '12 at 12:09
    
has this been useful to you? –  Nikhil Mulley Jan 6 '12 at 16:49

1 Answer 1

up vote 5 down vote accepted

from man ftp on my CentOS

 If auto-login is enabled, ftp will check the  .netrc  (see  below)
              file  in the user’s home directory for an entry describing an account on the remote machine.  If no entry exists, ftp will prompt for the
              remote machine login name (default is the user identity on the local machine), and, if necessary, prompt for a password  and  an  account
              with which to login.

Example: ~/.netrc

machine ftp.freebsd.org
    login anonymous
    password mynameis@wonderful.com

machine myownmachine
    login useraccount
    password xyz

More on .netrc file in the man page:

THE .netrc FILE
       The .netrc file contains login and initialization information used by the auto-login process.  It resides in the  user’s  home  directory.   The
       following tokens are recognized; they may be separated by spaces, tabs, or new-lines:

       machine name
              Identify  a  remote  machine  name.   The auto-login process searches the .netrc file for a machine token that matches the remote machine
              specified on the ftp command line or as an open command argument.  Once a match is made, the  subsequent  .netrc  tokens  are  processed,
              stopping when the end of file is reached or another machine or a default token is encountered.

       default
              This  is  the  same  as machine name except that default matches any name.  There can be only one default token, and it must be after all
              machine tokens.  This is normally used as:

                   default login anonymous password user@site

              thereby giving the user automatic anonymous ftp login to machines not specified in .netrc.  This can be overridden by using the  -n  flag
              to disable auto-login.

       login name
              Identify  a user on the remote machine.  If this token is present, the auto-login process will initiate a login using the specified name.

       password string
              Supply a password.  If this token is present, the auto-login process will supply the specified string if the  remote  server  requires  a
              password as part of the login process.  Note that if this token is present in the .netrc file for any user other than anonymous, ftp will
              abort the auto-login process if the .netrc is readable by anyone besides the user.

       account string
              Supply an additional account password.  If this token is present, the auto-login process will supply the specified string if  the  remote
              server requires an additional account password, or the auto-login process will initiate an ACCT command if it does not.
share|improve this answer
    
@BenD has this been useful to you? –  Nikhil Mulley Jan 6 '12 at 16:50
    
Thank you, that's exactly what I was looking for. –  Ben D Jan 7 '12 at 12:05
    
This is perfect - thanks! :D –  kivetros Feb 17 '12 at 21:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.