Operating System - HP-UX
1830354 Members
2254 Online
110001 Solutions
New Discussion

ftp scripting syntax error

 
Jim Spencer
New Member

ftp scripting syntax error

I have read the postings on ftp scripts here. Any suggestions for how to resolve the error shown below?
Thanks. Here is the code.

19 host="tamdev1"
20
21 clear
22 echo "Enter to file to transfer. \c "
23 read file
24 echo $file
25
26 echo "Enter directory path. \c"
27 read path
28 echo $path
29
30 echo "Enter user name. \c"
31 read user
32 echo $user
33
34 echo "Enter password. \c"
35 read pass
36 echo $pass
37
38
39 for i in $host
40 do
41 ftp -i -v -n < 42 open $i
43 user $user $pass
44 cd $path
45 put $file
46 bye
47 EOF
48 done

Here is the code running.

Enter to file to transfer. lltamqa1
lltamqa1
Enter directory path. /home/jspencer
/home/jspencer
Enter user name. root
root
Enter password. (I replaced the pw here for posting on the web)
**********
./dist.sh[39]: Syntax error at line 41 : `<<' is not matched.
10 REPLIES 10
Patrick Wallek
Honored Contributor

Re: ftp scripting syntax error

I think you need a space between the << and the EOF.

ftp ........ << EOF
Jim Spencer
New Member

Re: ftp scripting syntax error

I included a space. Unfortunately it returned the same results, exactly.
Tracey
Trusted Contributor

Re: ftp scripting syntax error

I tried it on my machine too, evidently ftp does not like EOF. I tried using the default bang ! and it worked.
Patrick Wallek
Honored Contributor

Re: ftp scripting syntax error

I think that is correct, it doesn't like EOF. I used ENDFTP and it worked as well.
Joseph C. Denman
Honored Contributor

Re: ftp scripting syntax error

I think it has something to do with your loop. Have you tried taking the ftp out of the loop. I have used EOF and ftp many times in the past.
If I had only read the instructions first??
Charles Harris
Super Advisor

Re: ftp scripting syntax error

Your script looks okay to me, I've just tried it on one of our servers with no problem.

You could try deleting the ftp line in the script (and the EOF), retyping it just to make sure there are no spurious CR's or strange Vi 'isms...
The only other suggestion is adding #!/sbin/sh to the top of your script or check to see what shell you are running.

Hope this helps!
Jim Spencer
New Member

Re: ftp scripting syntax error

The answer to the problem has been revealed. Although it does not show in the pasting of the script to the web site, the ftp commands were indented. Removing the white space at the beginning of lines 42-46 resulted in the script succeeding.

Thanks for all of the rapid responses. This is my first posting. I think I will be back to post again.

41 ftp -i -v -n <<-EOF
42 open $i
43 user $user $pass
44 cd $path
45 put $file
46 bye
47
48 EOF
MAD_2
Super Advisor

Re: ftp scripting syntax error

Great, the answer to the problem revealed at the bottom also helped me. I was experiencing the exact same problem and tried to find an answer everywhere, nowhere it mentioned that the indentations in the ftp portion of the script could represent a problem.

Excellent!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Bill Hassell
Honored Contributor

Re: ftp scripting syntax error

The indentation problem is a very common for here-documents. The terminating string must be left-justified for << but may be indented by using the <<- construct. The man pages for sh-posix and ksh both say leading tabs (look for here-document) but it does not mean white space (spaces or tabs). This means that EOF will not work as a terminator, but EOF will work OK.

For readability, I like to indent the here-document but left-justify the beginning line and also the terminating line. Adn as you've seen, the HP Forums display method automatically removes leading white space from all text and also reduces repeated white space within the posted text to a single space.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: ftp scripting syntax error

The indentation problem is a very common for here-documents. The terminating string must be left-justified for << but may be indented by using the <<- construct. The man pages for sh-posix and ksh both say leading tabs (look for here-document) but it does not mean white space. So EOF won't work at all (even with <<-) but EOF will.

For readability, I like to indent the here-document but left-justify the beginning line and also the terminating line. And as you've seen, the HP Forums display automatically removes leading white space from all text and also redurces repeated white space within the posted text to a single space.


Bill Hassell, sysadmin