| | |
Automating an FTP upload
Thread Solved
![]() |
•
•
Join Date: Jul 2006
Posts: 3
Reputation:
Solved Threads: 0
Hello,
I have stared at this script for the last two days and am unable to find the cause of my error message. Any help would be greatly appreciated.
The script is
I have removed some of the site specifics but this is the basic script. If I remove the For loop and If condition and just specify the file name, the ftp works. Introduction of the loops causes:
each time. The error is always listed as one line past the length of the script. I am completely baffled as to what I am missing in this script.
I have stared at this script for the last two days and am unable to find the cause of my error message. Any help would be greatly appreciated.
The script is
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/sh for i in '/xxx/*' do if [ -f /xxx/$i ] then HOST='xxx.xxx.com' USER='xxxx' PASSWD='xxxx' FILE='$i' ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD ascii put $FILE END_SCRIPT fi done
I have removed some of the site specifics but this is the basic script. If I remove the For loop and If condition and just specify the file name, the ftp works. Introduction of the loops causes:
Shell Scripting Syntax (Toggle Plain Text)
uploader.sh: 19: Syntax error: end of file unexpected (expecting "fi")
each time. The error is always listed as one line past the length of the script. I am completely baffled as to what I am missing in this script.
I coould be completely wrong, because I always put it against the left edge anyway, but I believe the "END_SCRIPT" marker you are using to end the so-called here document, needs to be against the left hand side, in otherwords at the beginning of the new line.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Aug 2006
Posts: 2
Reputation:
Solved Threads: 1
•
•
•
•
Hello,
I have stared at this script for the last two days and am unable to find the cause of my error message. Any help would be greatly appreciated.
The script is
I have removed some of the site specifics but this is the basic script. If I remove the For loop and If condition and just specify the file name, the ftp works. Introduction of the loops causes:Shell Scripting Syntax (Toggle Plain Text)
#!/bin/sh for i in '/xxx/*' do if [ -f /xxx/$i ] then HOST='xxx.xxx.com' USER='xxxx' PASSWD='xxxx' FILE='$i' ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD ascii put $FILE END_SCRIPT fi done
each time. The error is always listed as one line past the length of the script. I am completely baffled as to what I am missing in this script.Shell Scripting Syntax (Toggle Plain Text)
uploader.sh: 19: Syntax error: end of file unexpected (expecting "fi")
Hope this helps - here is expect: http://sourceforge.net/projects/expect
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 1
Greetings,
The method you are using is going to hammer the ftp with a connect and disconnect for every file in that dir. I have re-wrote it to make it more connection friendly, I would consider using the for loop on the send only. Like so:
#!/bin/sh
# Declare Variables
HOST='xxx.xxx.com'
USER='xxxx'
PASSWD='xxxx'
# Start FTP Connection
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
ascii
# Initiate Loop for Sending File
for file in '/xxx/*'
do
if [ -f /xxx/$file ]
then
put $FILE
fi
done
END_SCRIPT
The method you are using is going to hammer the ftp with a connect and disconnect for every file in that dir. I have re-wrote it to make it more connection friendly, I would consider using the for loop on the send only. Like so:
#!/bin/sh
# Declare Variables
HOST='xxx.xxx.com'
USER='xxxx'
PASSWD='xxxx'
# Start FTP Connection
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
ascii
# Initiate Loop for Sending File
for file in '/xxx/*'
do
if [ -f /xxx/$file ]
then
put $FILE
fi
done
END_SCRIPT
Last edited by toztech; Sep 11th, 2006 at 4:17 pm.
•
•
Join Date: Sep 2006
Posts: 30
Reputation:
Solved Threads: 1
If you want to indent you can use the indent option for inline files:
Note the dash before the introduction to the inline file.
Shell Scripting Syntax (Toggle Plain Text)
if [[ something ]] ; then ftp -n $HOST <<-END_SCRIPT ... ftp commands ... END_SCRIPT fi
Note the dash before the introduction to the inline file.
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Solved Threads: 1
hi
can anybody help me in automating ftp. following is my program
#!/bin/sh
HOST="192.168.1.227"
USERNAME="ganesh"
PASS="ganesh123"
ftp -n -v $HOST << EOF
USER $USERNAME
PASSWORD $PASS
bin
hash
prompt
get messages.properties
bye
EOF
i have problem in login the FTP
can anybody help me in automating ftp. following is my program
#!/bin/sh
HOST="192.168.1.227"
USERNAME="ganesh"
PASS="ganesh123"
ftp -n -v $HOST << EOF
USER $USERNAME
PASSWORD $PASS
bin
hash
prompt
get messages.properties
bye
EOF
i have problem in login the FTP
Start your own thread.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- FTP Upload Setup (Windows NT / 2000 / XP)
- Renaming FTP upload (ColdFusion)
Other Threads in the Shell Scripting Forum
- Previous Thread: comparing versions
- Next Thread: Colorful clock of Time
| Thread Tools | Search this Thread |






