FTP inside shell script not working

My host updated my version of FreeBSD, and now one of my scripts is broken. The script simply uploads the data feed to Google for its trading service.

script (which worked before the update):

ftp ftp://myusername: mypassword@uploads.google.com /<<END_SCRIPT ascii put /usr/www/users/myname/feeds/mymerchantfile.txt mymerchantfile.txt exit END_SCRIPT 

Now the script says "unknown host". The same script runs on OSX.

I tried to remove "ftp: //". - No effect. I can log in from the command line if I enter the username and password manually.

I searched for other solutions and also tried the following:

 HOST='uploads.google.com' USER='myusername' PASSWD='mypassword' ftp -dni <<END_SCRIPT open $HOST quote USER $USER quote PASS $PASS ascii put /usr/www/users/myname/feeds/mymerchantfile.txt mymerchantfile.txt END_SCRIPT 

and

 HOST='uploads.google.com' USER='myusername' PASSWD='mypassword' ftp -dni <<END_SCRIPT open $HOST user $USER $PASS ascii put /usr/www/users/myname/feeds/mymerchantfile.txt mymerchantfile.txt END_SCRIPT 

Nothing I can find on the Internet seems to do the trick. Does anyone have any other ideas? I do not want to use the .netrc file as it is being executed by cron under another user.

+4
source share
5 answers

ftp(1) shows that there is a simple -u command line switch to download the file; and since ascii is the default (shudder), perhaps you can replace your entire script with one command line:

 ftp -u ftp://username: password@uploads.google.com /mymerchantfile.txt\ /usr/www/users/myname/feeds/mymerchantfile.txt 

(long line wrapped \\n feel free to remove the backslash and put it on one line.)

+1
source
 ftp $HOSTNAME <<EOFEOF $USER $PASS ascii put $LOCALFILE $REMOTETEMPFILE rename $REMOTETEMPFILE $REMOTEFINALFILE EOFEOF 

Please note that the above code can be easily broken, for example, using spaces in the variables in question. In addition, this method practically does not allow to detect and process a failure.

Look at the wait tool if you haven’t already. You may find that it solves problems you did not know about.

0
source

Some ideas:

just a thought, since this is done in a subshell that must be correctly inherited from the parent, does env make any difference when executed from a script than from a shell?

Are you using the correct "shebang"?

Any proxy requiring authentication?

Can you ping a host?

0
source

In BSD, you can create a NETRC script that ftp can use to log in. You can even specify the NETRC file in your ftp command using the -N option. Otherwise, the default value is NETRC (which is $HOME/.netrc ).

0
source

Can you check if there is a difference in environment between your shell name and cron job? From your login, run env and pay attention to ftp_proxy and http_proxy .

Then include the line in the cron job that will unload the environment, for example. env >/tmp/your.env .

Maybe there is some difference ... Also, have you double checked the correct use of the -n switch?

0
source

All Articles