I am recently working extensively with a remote system via ftp connection, since the session time is so short that I have to re-login quite often when I finish my work on my local machine, so I need a way to create a custom command/shell script to login to the ftp server with just one word, but the question is how to do it.


~$ ftp domainname.com
 Name (domainname.com): MyName
 Password: xxxx
  • 1
    Just a question, why ftp and not ssh? ssh is much more secure and logging in like this would just be a simple bash alias – n0pe Sep 12 '11 at 17:32
  • 1
    Also, with SSH you can use authentication keys as well which will automatically log you in without having to store your username/pass in a .bashrc file as plain text. – sbtkd85 Sep 12 '11 at 17:41
  • well, I suppose the remote system has support for ssh, but it doesn't. – Rn2dy Sep 12 '11 at 17:49

Usually, ftp command line clients support the configuration file ~/.netrc where you can configure credentials for remote systems, e.g.:

machine legacy.system.example.org
login juser
password keins

When you ftp legacy.system.example.org then you don't have to retype this information anymore.

If you need to do more automation, you can script ftp via piping commands into it, e.g.:

$ cat pushit.sh
# complex logic to set
ftp <<EOF

Sure, if the system does not support ssh, it probably does not support ftps either - but you can try it (e.g. via ftp-ssl) if you need to secure your connection.


An alternative to one of the plain ftp commands is to use lftp, since it provides several features to automated login and command execution.


$ lftp -e 'source ~/login.lftp'
$ cat login.lftp
open sftp://juser:geheim@backup.example.net
cd /path/to/favorite/dir

Note that this example shows automated password authentication to a SFTP server which is not supported by the standard OpenSSH sftp client.

The option -e instructs lftp to execute the commands at startup and stay interactive.

Of course, such a lftp script mach also source other scripts, and also automatically disconnect from the server.

In contrast, with -c or -f lftp directly exits after executing the commands specified as argument or read from the specified file.

  • 2
    LFTP is much better. – Ekeyme Mo Jan 11 '17 at 3:18

If you want to script out the whole thing:


quote USER $USER
put $FILE
exit 0

See also this web page.


If you want to automatically log in, you can use a .netrc file. I would NOT recommend this as you would have to store your username and password in plain text which is unsecure. If you can use ssh, then I'd recommend using that with authentication keys to automatically log you in.

If you cannot use a secure method such as ssh with keys, you can configure your ftp information by following this guide.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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