Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 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.

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

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.

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

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.