I've read several questions related to this matter, but none of them seems to have a valid answer to my problem. I just need to write a simple bash script to get a couple of files via an FTP connection.

The normal script was this

#!/bin/bash
username="myFTPusername"
password="myFTPpass"
ftp -in hostname <<EOF
quote USER $username
quote PASS $password
lcd mylocaldirectory
cd FTPfolder
get filename
bye
EOF

And I've also tried this command, seen here

wget -O filename ftp://user:pass@hostname/filename

But none of them work. Weid enough, I can access without problems without the script, and my user and password work fine. But when I try to connect via the script or the wget command, I get a "login incorrect".

Is there some kind of limitation on the password format? It has different characters, and one of them is a "$". My only guess is that that dollar sign is the problem in the script. Any ideas to solve it? What if I coulnd't change that FTP pass?

link|improve this question

77% accept rate
feedback

2 Answers

up vote 2 down vote accepted

Using wget (or curl) is probably your best bet. If your password contains shell metacharacters (like '$'), you'll need to quote it on the command line. For example:

wget -O filename 'ftp://user:pass@hostname/filename'

Using single quotes inhibits the expansion of '$' inside the quoted string.

link|improve this answer
That was the answer ;) Good job larsks, thank you so much! – javipas Jun 16 '11 at 17:06
feedback

Rather than store the authentication details in the script, try putting them in ~/.netrc, this should get around any problems with the shell expanding the $ character in your password.

link|improve this answer
Mmm thanks for the suggestion. The wget solution is simpler and works, but I'll try yours as well. Thanks! – javipas Jun 16 '11 at 17:07
feedback

Your Answer

 
or
required, but never shown

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