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 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.

e.g.

~$ ftp domainname.com
 ...
 Name (domainname.com): MyName
 ...
 Password: xxxx
 ...
 ftp>
share|improve this question
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 –  maxmackie 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. –  baboonWorksFine Sep 12 '11 at 17:49

3 Answers 3

up vote 3 down vote accepted

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
# EXAMPLE_FILE=
ftp <<EOF
prompt
mput $EXAMPLE_FILE
quit
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.

share|improve this answer

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.

share|improve this answer

If you want to script out the whole thing:

#!/bin/sh
HOST='ftp.example.com'
USER='yourid'
PASSWD='yourpw'
FILE='file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

See also this web page.

share|improve this answer

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.