Results 1 to 7 of 7
Dear all
I use following code to execute ftp action
Code:
((ftp -vn ${TARGET_HOST} << EOP) > $MSG_LOG ) 2> $ERR_LOG
user $FTP_USER $FTP_PS
hash
#prom
lcd $SOURCE_DIR
cd $TARGET_DIR
...
- 04-17-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 3
Bash Script problem for ftp
Dear all
I use following code to execute ftp action
The code can work correctly.Code:((ftp -vn ${TARGET_HOST} << EOP) > $MSG_LOG ) 2> $ERR_LOG user $FTP_USER $FTP_PS hash #prom lcd $SOURCE_DIR cd $TARGET_DIR put ${iFILE} bye
But when I put these code into for loop , it can't work!
The error message is 'syntax error: unexpected end of file'
But I have used dos2unix to change the script format
Are there any wrong of my code?
The complete code as follow.
Code:#!/usr/bin/sh ### Declare Variable ### TARGET_HOST="192.168.1.12" FTP_USER="abc" FTP_PS="123" SOURCE_DIR="/home/avseqw/abc" TARGET_DIR="/home/avseqw/abc" SOURCE_FILE="*" MSG_LOG="FTP.MSG" ERR_LOG="FTP.ERR" OK_MSG="File receive OK" apArray=(abc def) apPath=(/home/avseqw/abc /home/avseqw/def) apServer=(192.168.1.12 192.168.1.13) apUser=(abc abc) apPass=(123 123) targetDir=(/home/avseqw/abc /home/avseqw/def) #iFILES=`(find ${apPath[0]} -type f)` #echo ${iFILES[*]} for (( i=0; i<${#apArray[*]}; i=i+1 )) do iFILES=`(/usr/bin/find ${apPath[$i]} -type f)` for iFILE in ${iFILES} do ((ftp -vn ${TARGET_HOST} << EOP) > $MSG_LOG ) 2> $ERR_LOG user $FTP_USER $FTP_PS hash #prom lcd $SOURCE_DIR cd $TARGET_DIR put ${iFILE} bye done done
- 04-17-2008 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
You forgot to signify the end of your input with EOP
Code:do ((ftp -vn ${TARGET_HOST} << EOP) > $MSG_LOG ) 2> $ERR_LOG user $FTP_USER $FTP_PS hash #prom lcd $SOURCE_DIR cd $TARGET_DIR put ${iFILE} bye EOP done
- 04-18-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 3
Thanks for your reply!
I try to add "EOP" in the code.
But it still didn't work
The error message is 'syntax error: unexpected end of file' as before.
I use ultraedit to modify the script and use FileZilla to ftp to the server.
Then I use dos2unix command to change the script fomat.
Does the error result from which step?
- 04-18-2008 #4
Run the script with
Code:$ sh -x [name of script]
Men occasionally stumble over the truth,
but most of them pick themselves up
and hurry off as if nothing had happened.
Winston Churchill
... then the Unix-Gods created "man" ...
- 04-18-2008 #5Just Joined!
- Join Date
- Apr 2008
- Posts
- 3
I have used the sh -x command.
The error message is "syntax error: unexpected end of file" as before.
I try to write a function in another script as below
The code is the same as my post before.
Then I call the ftp function in my main script , it works successfully!Code:function ftpFile { ((ftp -vn ${1} << EOD) > ${8} ) 2> ${9} user ${2} ${3} #ascii prompt off cd ${6} put ${5} ${7}.bak rename ${7}.bak ${7} bye EOD }
But when I put the code in the for loop in my main script , it occurs "syntax error: unexpected end of file" error message.
I was confused by the problem in several days.Last edited by avseqw; 04-18-2008 at 02:00 AM. Reason: add content
- 05-06-2008 #6Just Joined!
- Join Date
- May 2008
- Posts
- 2
you forgott to delete the tabs or spaces befor "EOP" and there is a blank to much after <<.
this will work:
Code:((ftp -vn ${TARGET_HOST} <<EOP) > $MSG_LOG ) 2> $ERR_LOG user $FTP_USER $FTP_PS hash #prom lcd $SOURCE_DIR cd $TARGET_DIR put ${iFILE} bye EOP
- 05-06-2008 #7Just Joined!
- Join Date
- Apr 2008
- Posts
- 35
Hey There,
You can also use <<- instead of << if you want your "here doc" to account for/strip any leading spaces or tabs.
Just a suggestion. Otherwise the answers are good
, Mike


Reply With Quote