FTP script error

[COLOR=black]This question has been answered many times. I tried to use some examples. Here is the error and cannot find the reason. Please help!

messages :
[FONT=r_ansi]40
step1
step2
arcfile1.sh: line 55: syntax error: unexpected end of file :frowning:

here is the script:

#!/bin/bash
DATE=`date +%Y%m%d`
TIME=`date +%H%M%S` 
LOGFILE="process$(date '+%y%m%d')"
mFile="/name1/name2/name3/"
 
# Count files
ls -1 $mFile >> $LOGFILE.log
file_ctr=`egrep -cv '#|^$' /name1/name2/$LOGFILE.log` 
echo "$file_ctr"
 
echo "step1"
# User and host info
HOST='host.com'
FTPUSER='user'
PASSWD='password'
 
# Upload to ftp - ftp.log - all ftp messages 
echo "step2"
while read line
do 
 
echo "step3"
#Start FTP session 
ftp -v -n $HOST > /name1/name2/name4/ftp.log <<EOF 
user $FTPUSER
pass $PASSWD 
 
#change to the correct directory 
cd name11
cd name12


#change to binary transfer mode 
bin 
prompt 
mput $line 
bye
EOF 
done </name1/name2/$LOGFILE.log
ftp_ctr=`cat /name1/name2/name4/ftp.log | grep 226 | wc -l`  
if [ "$ftp_ctr" = "$file_ctr" ]; then
echo "No Error"
echo "List of transferred files:" >> ./transfer.txt
else
echo "Error has occured"
echo "List of transferred files:" >> ./error.txt
fi

The usual problems are:

1) Script file transferred from Windows platform without proper conversion of the line terminators.
Check with:
sed -n l script_filename

2) The line containing just "EOF" does not start in column one.
(Hard to tell because you have not used code tags).

3) Missing quotes ... like this line:

methyl,
I appreciate your quick response thank you , but

  1. all files and the scrip are placed in UNIX folder

  2. the ftp section works fine if it is not in �while do done� loop

  3. HOST ='host.com' is OK in the script..

This is strange, but when I changed EOF to ! it worked!

(bearing in mind that I had to change some things to get it to run anyway).

Don't understand that!

Update: No. I'm talking rubbish! I must have changed something else. I'm on it! :slight_smile:

---------- Post updated at 08:04 PM ---------- Previous update was at 07:55 PM ----------

Hi.

OK.

You have a space after the closing EOF!

Back to

sed -n l script_filename

There are spurious trailing space characters on many lines in the script (many of which do not matter). The one on the "EOF" line is causing the main problem.

Also are there two concurrent inward redirects?

You mean one for the while loop and one for the ftp?

Then I suppose there is. But the ftp one is being fed by the garb between the EOF's, no?

I didn't test it to that level, but if that's a problem, it's nothing an exec couldn't fix.

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Hi and thank you,

I obtain the solution for this trouble, I removed the white space before
ftp -v -n $HOST <<-EOF and
EOF

I have one more question:
Is there any way to get �226 Transfer complete� for each transferred file (?
The ftp.log looks like that (550 Folder /name11/name12 not found ..... ):

Connected to host.com.
220 host.local X2 WS_FTP Server 7.0(12500000)
504 unknown security mechanism
504 unknown security mechanism
331 Enter password
230 User logged in
550 Folder /name11/name12 not found
200 Transfer mode set to BINARY
221 bye

Were files actually transferred?

550 Folder /name11/name12 not found

no :frowning:

---------- Post updated at 02:22 PM ---------- Previous update was at 01:55 PM ----------

I changed the script to
cd name11
cd name 12
( instead of cd \name11\name12 )

and there is no more 550 folder /name11/name12 not found

All that suggests to me is the /name11 is not in the root directory...

ls -1 $mFile >> $LOGFILE.log - creates the LOGFILE.log:

file1.txt
file2.txt
file3.txt

How to add the path in the LOGFILE.log ?

\name1\name1\name3\file1.txt
\name1\name1\name3\file2.txt
\name1\name1\name3\file3.txt

do lcd ( local change directory) to where these files exist.

i.e. \name1\name1\name3\

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 03:39 PM ---------- Previous update was at 03:36 PM ----------

ls -1 $mFile | sed 's/^/\\name1\\name1\\name3\\&/g' >> $LOGFILE.log

Perhaps you could change the

ls -1 ...

to something like

find $mFile* -prune ...

didn't work:

when use find $mFile* -prune ... , the LOGFILE is:
/name1/name2/name3

when use find $mFile* ... , the LOGFILE is:
/name1/name2/name3
/name1/name2/name3/file1.txt
/name1/name2/name3/file2.txt
/name1/name2/name3/file3.txt

We're kind of running low on guessing gas.
Could you possibly elaborate what you're trying and what exactly didn't work?

Here is the FTP error, after changing the FTP script:

ftp.log:
Connected to host.com.
220 host.local X2 WS_FTP Server 7.0(34062500)
504 unknown security mechanism
504 unknown security mechanism
331 Enter password
230 User logged in
250 Command CWD succeed
250 Command CWD succeed
200 Transfer mode set to BINARY
mput /name1/name2/name3/file10.txt? 227 Entering Passive Mode (10,25
550 Command STOR failed
221 bye

and here is the script:

#!/bin/bash
DATE=`date +%Y%m%d`
TIME=`date +%H%M%S` 
LOGFILE="process$(date '+%y%m%d')"
mFile="/name1/name2/name3/*.txt"

# Count files
find $mFile  >> $LOGFILE.log
file_ctr=`egrep -cv '#|^$' /name1/name2/$LOGFILE.log` 
echo "$file_ctr"

# User and host info
HOST=host.com'
FTPUSER='user'
PASSWD='password'

# Upload to ftp  -  ftp.log  - all ftp messages 
while read line
do  
ftp -v -n $HOST > /name1/name2/name4/ftp.log <<EOF 
user $FTPUSER
pass $PASSWD 
cd name11
cd name12
bin 
prompt 
mput $line 
bye
EOF 
done </name1/name2/$LOGFILE.log

ftp_ctr=`cat /name1/name2/name4/ftp.log | grep 226 | wc -l` 
if [ "$ftp_ctr" = "$file_ctr" ]; then
echo "No Error"
echo "List of transferred files:" >> ./transfer.txt
else
echo "Error has occured"
echo "List of transferred files:" >> ./error.txt
fi

I've never seen this three times in one post!

Looks to me that the prompt command is not working. It appears to be prompting you to see if that is the file to transfer. Hence the ? in

200 Transfer mode set to BINARY
mput /name1/name2/name3/file10.txt? 227 Entering Passive Mode (10,25
550 Command STOR failed

It is asking you to respond to the question. After the BINARY line you should get something to the effect

Interactive mode Off