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 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.

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

:p

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

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

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.

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

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?

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

Expect is definitely the way to go... OR you could generate a list of files first (store them in a variable or temporary file), and use ncftpput to do the work, no expect or << required!

This question has already been answered. Start a new discussion instead.