Bash – Too complex password for a FTP bash script

bashftppasswordscripting

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?

Best Answer

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.