1

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?

javipas
  • 1,332
  • 3
  • 23
  • 38

2 Answers2

4

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.

larsks
  • 43,623
  • 14
  • 121
  • 180
1

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.

theotherreceive
  • 8,365
  • 1
  • 31
  • 44
  • 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