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!

Can't ftp within if statement 2

Status
Not open for further replies.

jawon

Programmer
Feb 6, 2003
31
0
0
US
I'm trying to ftp in a file if it doesn't already exist on my local host. The code is something like this...

mydir=/mydir
if [[ ! -s myfile ]]
then
ftp << EndFTP
open remotehost
ascii
prompt
cd /opt/newdir
get remotefile.log $mydir/myfile
close
EndFTP
fi

But I get the following error...
syntax error at line 40 : `<<' unmatched

What to do?
 
ftp -n <<EndFTP
....
EndFTP

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Nope, that doesn't do it. Same error. And I do want to auto login. Any other ideas? Thanks.
 
You have a space after '<<' - there should be no space:

ftp <<EndFTP

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Actually it's the spaces or tabs in front of the final [tt]EndFTP[/tt] that are causing the problem. Also the tabs or spaces you are using to indent the other commands can cause problems with some utilities.

To have the &quot;here file&quot; ignore the leading whitespace, invoke the ftp like this...
[tt]
mydir=/mydir
if [[ ! -s myfile ]]
then
ftp <<-EndFTP
open remotehost
ascii
prompt
cd /opt/newdir
get remotefile.log $mydir/myfile
close
EndFTP
fi
[/tt]
That dash in the &quot;[tt]<<-EndFTP[/tt] part means to ignore all leading space when using these commands.

Otherwise your EndFTP would need to be left justified to be &quot;seen&quot;.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top