Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting FTP in a 'for' loop

Status
Not open for further replies.

gbanke

Technical User
Nov 15, 2001
24
0
0
US
Okay UNIX gurus, I'm at a loss. I've written a /bin/sh script that places ftp commands into a 'for' loop that appears thusly:

for FILES in `ls directory/`
do
`ftp -n server <<eoj
user name password
lcd localdir
cd remotedir
binary
put $FILES
bye
eoj`
done

The script works just fine, but after each iteration through the loop it generates the error:
./script: Local: command not found

It's irritating the heck out of me and I've tried every incantation and combination of backticks and quoting that I can think of to prevent it. Nothing has worked yet.

Any ideas?
 
This might sound crazy but check the value of your PATH and make sure that the enviroment variable is being exported.

From what the error states it sounds like the subshell process might not being setting up the environment the same way as the parent process.


HTH

Steve
 
Steve,

Thanks. I checked the environment variables and added exporting to my script. No luck. Same problem. In fact, it seems to be getting confused about the last ftp statement, in this case the eoj. If I remove the eoj and place the terminating backtick on the bye command above it, I get the same error. ftp is choking on the last command with a backtick. If I remove the backticks, the script fails with an 'unexpected end of file' error. Guess I'm stuck with the lesser of 2 evils. The scripts runs, but sets a bogus rval due to this problem. Makes error checking a chore.

Gary <><
 
Have you considered making your script write a .netrc with an &quot;init&quot; macro?

[tt]~/.netrc (mode 600 please, thanks)
machine a.random.server login jsmith password a
macdef init
an ftp command
another ftp command
more ftp commands

quit
leave this line blank
leave this line blank too, it's needed for macro separation

[/tt]

Then call the whole mess with &quot;ftp a.random.server&quot; and it'll connect, login, and do the &quot;init&quot; macro all automatically.
 
Just a point, I have never seen 'eoj' before I always use EOF for end-of-file and use `ftp -i -n -v <<EOF`.
 
AIXSPadmin: you can use any string after <<. The shell use all lines up to the line starting with the same string as input for the command.

gbanke: remove the backquotes around ftp.
In fact you ask the shell to execute the lines printed by ftp. The first line ftp print must start with 'Local' and the shell tries to execute a Local command which of course does not exists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top