If I run the wget command listed below in the script by itself on the command line, it works fine and downloads all the files I specify. If I run the wget in a script with the ftp command directly after it, it does not download the files, but the ftp command successfully deletes them. I have no idea why this is happening. Shouldn’t the wget command complete fully before passing off control to the ftp command to execute?
I’m using Windows 7 with Cygwin installed. Below is the contents of fileFetcher.sh which I run with bash fileFetcher.sh. For both the script and the output I’ve edited some things to remove usernames, passwords, and hostnames.
Also I would like to mention I don’t really understand the < < END_SCRIPT construction that I used. I found it on another website and customized it for this script. It seems like it lets me embed a script inside a script. I don’t know if this is somehow the source of an error.
Again both these commands work fine /by themselves/ but once they’re in the script they don’t play nice together.
wget -r -l1 -nd --no-parent -A.tgz -t3 --user='username' --password='password' ftp://ftp.hostname.org/backups/
ftp -n -i -d ftp.hostname.org <<END_SCRIPT
quote USER username
quote PASS password
cd backups
mdelete *.tgz
ls
quit
END_SCRIPT
exit 0
Below this line is the output from the bash script being run. The wget command runs first, and DOES NOT download the files.
$ bash fileFetcher.sh
--2012-02-07 23:00:46-- ftp://ftp.hostname.org/backups/%0D
=> `.listing'
Resolving ftp.hostname.org (ftp.hostname.org)... 200.205.124.20
Connecting to ftp.hostname.org (ftp.hostname.org)|200.202.137.60|:21... connected.
Logging in as username ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /backups ... done.
==> PASV ... done. ==> LIST ... done.
[ <=> ] 467 --.-K/s in 0s
2012-02-07 23:00:47 (6.41 MB/s) - `.listing' saved [467]
Removed `.listing'.
--2012-02-07 23:00:47-- ftp://ftp.hostname.org/backups/%0D
=> `%0D'
==> CWD not required.
==> SIZE \r ... done.
==> PASV ... done. ==> RETR \r ...
No such file `\r'.
Below this line the ftp portion of the shell script logs in and deletes the files properly.
---> USER $username
---> PASS $password
---> CWD backups
---> TYPE A
---> PORT 192,168,0,91,223,12
---> NLST *.tgz
---> TYPE A
---> DELE website backup 2012-02-07 20-18-48.tgz
---> DELE website backup 2012-02-07 20-18-49.tgz
---> DELE website backup 2012-02-07 20-18-50.tgz
---> PORT 192,168,0,91,223,13
---> NLST
.
..
---> QUIT
The
\r‘s in the output (there’s a telltale%0Din there, too) indicate a problem. A Cygwin shell script must use Unix line endings (\n) and not DOS/Windows line endings (\r\n).