Automating an FTP upload

Thread Solved

Join Date: Jul 2006
Posts: 3
Reputation: medaugh is an unknown quantity at this point 
Solved Threads: 0
medaugh medaugh is offline Offline
Newbie Poster

Automating an FTP upload

 
0
  #1
Jul 20th, 2006
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

Shell Scripting Syntax (Toggle Plain Text)
  1.  
  2. #!/bin/sh
  3. for i in '/xxx/*'
  4. do
  5. if [ -f /xxx/$i ]
  6. then
  7. HOST='xxx.xxx.com'
  8. USER='xxxx'
  9. PASSWD='xxxx'
  10. FILE='$i'
  11. ftp -n $HOST <<END_SCRIPT
  12. quote USER $USER
  13. quote PASS $PASSWD
  14. ascii
  15. put $FILE
  16. END_SCRIPT
  17. fi
  18. 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)
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,358
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Automating an FTP upload

 
0
  #2
Jul 20th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 3
Reputation: medaugh is an unknown quantity at this point 
Solved Threads: 0
medaugh medaugh is offline Offline
Newbie Poster

Re: Automating an FTP upload

 
0
  #3
Jul 20th, 2006
That worked great. Thanks for saving me from a very long weekend.

:p
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2
Reputation: zerobreach.com is an unknown quantity at this point 
Solved Threads: 1
zerobreach.com zerobreach.com is offline Offline
Newbie Poster

Re: Automating an FTP upload

 
0
  #4
Aug 23rd, 2006
Originally Posted by medaugh View Post
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

Shell Scripting Syntax (Toggle Plain Text)
  1.  
  2. #!/bin/sh
  3. for i in '/xxx/*'
  4. do
  5. if [ -f /xxx/$i ]
  6. then
  7. HOST='xxx.xxx.com'
  8. USER='xxxx'
  9. PASSWD='xxxx'
  10. FILE='$i'
  11. ftp -n $HOST <<END_SCRIPT
  12. quote USER $USER
  13. quote PASS $PASSWD
  14. ascii
  15. put $FILE
  16. END_SCRIPT
  17. fi
  18. 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)
  1. 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 wouldn't waste your time trying to shell this in this mannor. Use "expect" - once you have expect loaded which does come with most distros - just run autoexpect, and it will record your network activity of ftping. When your finished, just open the script and edit accordingly.

Hope this helps - here is expect: http://sourceforge.net/projects/expect
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 3
Reputation: toztech is an unknown quantity at this point 
Solved Threads: 1
toztech toztech is offline Offline
Newbie Poster

Re: Automating an FTP upload

 
0
  #5
Sep 11th, 2006
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
Last edited by toztech; Sep 11th, 2006 at 4:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 30
Reputation: sut is an unknown quantity at this point 
Solved Threads: 1
sut sut is offline Offline
Light Poster

Re: Automating an FTP upload

 
1
  #6
Sep 12th, 2006
If you want to indent you can use the indent option for inline files:

Shell Scripting Syntax (Toggle Plain Text)
  1. if [[ something ]] ; then
  2. ftp -n $HOST <<-END_SCRIPT
  3. ...
  4. ftp commands
  5. ...
  6. END_SCRIPT
  7. fi

Note the dash before the introduction to the inline file.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1
Reputation: ganeshbonde is an unknown quantity at this point 
Solved Threads: 1
ganeshbonde ganeshbonde is offline Offline
Newbie Poster

Re: Automating an FTP upload

 
0
  #7
Apr 11th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,358
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Automating an FTP upload

 
0
  #8
Apr 11th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC