943,809 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jul 20th, 2006
0

Automating an FTP upload

Expand 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
medaugh is offline Offline
3 posts
since Jul 2006
Jul 20th, 2006
0

Re: Automating an FTP upload

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 20th, 2006
0

Re: Automating an FTP upload

That worked great. Thanks for saving me from a very long weekend.

:p
Reputation Points: 10
Solved Threads: 0
Newbie Poster
medaugh is offline Offline
3 posts
since Jul 2006
Aug 23rd, 2006
0

Re: Automating an FTP upload

Click to Expand / Collapse  Quote originally posted by medaugh ...
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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
zerobreach.com is offline Offline
2 posts
since Aug 2006
Sep 11th, 2006
0

Re: Automating an FTP upload

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toztech is offline Offline
3 posts
since Sep 2006
Sep 12th, 2006
1

Re: Automating an FTP upload

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.
sut
Reputation Points: 20
Solved Threads: 1
Light Poster
sut is offline Offline
30 posts
since Sep 2006
Apr 11th, 2007
0

Re: Automating an FTP upload

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
ganeshbonde is offline Offline
1 posts
since Apr 2007
Apr 11th, 2007
0

Re: Automating an FTP upload

Start your own thread.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Aug 12th, 2010
0

Can't get FTP automation to work

I'm running on a Linux machine and can't get FTP uploads working. Here's my script:
HOST='ftp.name.com'
USER='username'
PASSWD='mypwd'
FILE='f1020811'
DIR='/data_dir/send'
echo **************************************************************
echo * Attempting FTP *
echo **************************************************************
ftp -n -u -d ftp.name.com <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put f1020811
END_SCRIPT

I noticed using $HOST was rejected. Replacing it with the actual ftp name worked. The script successfully logged on to the host, BUT the put failed with the message "no such file or directory". The file is in the current directory. Should there be a pathname?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
musicalsailor is offline Offline
5 posts
since Aug 2010
Jan 30th, 2011
0
Re: Automating an FTP upload
Thanks Masijade
This has solved my problem
I had the END_SCRIPT indented with one tab, and removing that has got it going.
MANY THANKS
Derek
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Derek001 is offline Offline
1 posts
since Jan 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: File backup cronjob
Next Thread in Shell Scripting Forum Timeline: facing issue in reading '*' from file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC