DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Shell Scripting (http://www.daniweb.com/forums/forum113.html)
-   -   Automating an FTP upload (http://www.daniweb.com/forums/thread50570.html)

medaugh Jul 20th, 2006 10:36 am
Automating an FTP upload
 
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

 
#!/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:

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.

masijade Jul 20th, 2006 3:08 pm
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.

medaugh Jul 20th, 2006 5:29 pm
Re: Automating an FTP upload
 
That worked great. Thanks for saving me from a very long weekend.

:p

zerobreach.com Aug 23rd, 2006 2:59 pm
Re: Automating an FTP upload
 
Quote:

Originally Posted by medaugh (Post 235630)
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

 
#!/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:

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

toztech Sep 11th, 2006 4:16 pm
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

sut Sep 12th, 2006 1:32 pm
Re: Automating an FTP upload
 
If you want to indent you can use the indent option for inline files:

if [[ something ]] ; then
    ftp -n $HOST <<-END_SCRIPT
        ...
        ftp commands
        ...
    END_SCRIPT
fi

Note the dash before the introduction to the inline file.

ganeshbonde Apr 11th, 2007 3:43 am
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

masijade Apr 11th, 2007 7:36 am
Re: Automating an FTP upload
 
Start your own thread.


All times are GMT -4. The time now is 4:15 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC