A ftp script

Hi guys

I'm writing my first shell script and I can't get rid of some errors.
First of all my shell is ash.
I've written the following script with the goal to log in on FTP server and calculate the throughput like number bytes transmitted (returned by get) /time for transmitting them.
The error tha I get when I execute my shell are:
Unresolved host -n
ftp>quote USER di leo
memory fault core dumped
Thank you in advance.

#!/bin/sh
HOST='10.0.0.201'
USER= 'dragon'
PASSWD= 'dragon'
FILE='/home/dragon/minix_modified/lance.c'
START=$(date+%s)
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
get $FILE >> NUMBYTES
END=$(date+%s)
DIFF=$(($END-$START))
THROUGHPUT= NUMBYTES/DIFF
quit
END_SCRIPT
exit 0

Firstly, I don't think your calculation should be done inside ftp.
Secondly, I am not sure about "get $FILE >> NUMBYTES", whether it will work or not.
Finally and most importantly, Please enable debugging using set -x and copy/paste its output for better troubleshooting.

#!/bin/sh
set -x
HOST='10.0.0.201'
USER= 'dragon'
PASSWD= 'dragon'
FILE='/home/dragon/minix_modified/lance.c'
START=$(date+%s)
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
get $FILE >> NUMBYTES
quit
END_SCRIPT
END=$(date+%s)
DIFF=$(($END-$START))
THROUGHPUT= NUMBYTES/DIFF
exit 0
set +x

Note: I hope you understand what the meaning of first line "#!/bin/sh
".

First of all thank you for your help.
Second I think I know the meaning of first line "#!/bin/sh, it should point out which interpreter use for your script.
To be more precise "#!" is a magic number of two bytes to identify a file or script like in this case. I'm learning script programming so I could have made some mistakes in this definition.

Any way I applied your corrections and this is the output
(Note: to log in I don't need a password so I set PASSWORD='' and the ftp server is a windows workstation


+HOST=192.168.1.6
+USER=domenik
domenik: No such file or directory
+PASSWD=
:Permission denied
+FILE=/minix/minix_modified/lance.c
+date%s
date+%s: No such file or directory
+START
+ftp -n 192.168.1.6
Memory fault - core dumped
+date%s
date+%s: no such file or directory
+END=
+-
-:No such file or directory
+DIFF=
+THROUGHPUT=NUMBYTES/DIFF
./ftp.sh:NUMBYTES/DIFF No such file or directory
+exit 0



Hi Sha,

You can try this script and let me know if you get any error

Code:
------

#!/bin/sh
set -x
HOST='10.0.0.201'
USER= 'dragon'
PASSWD= 'dragon'
DIR='/home/dragon/minix_modified/'
FILE='/home/dragon/minix_modified/lance.c'
LCL_PTH='C\Sample'
START=$(date+%s)
ftp -n $HOST <<END_SCRIPT
user $USER $PASSWD
binary
cd $DIR
lcd $LCL_PTH
get $FILE >> NUMBYTES
quit
END_SCRIPT
END=$(date+%s)
DIFF=$(($END-$START))
THROUGHPUT= NUMBYTES/DIFF
exit 0
set +x

Regards,
MPS:b:

no space after '=' and quote

Thanks psiva_arul

Unfortunately I keep on receiving errors messages:
Before I continue bore you, i think it's better how I access to the FTP server without script.
The FTP server is mozzila on win xp
1 I type: ftp 192.168.1.6
and I'm in the directory "minix"
2 I type my username: domenik
3 I type: "the bottom return" because I don't need to write any password
4 I type: cd minix_modified
5 I type: get lance.txt
6 I type: quit

After the "get" is displayed the bytes transferred that I'm interest to pick because I want to calculate the throughput
Thank for your help
The errors with your script are:

+date%s
date+%s: No such file or directory
+START
+ftp -n 192.168.1.6
Unresolved host -n
ftp>user root
You must "open" a connection first
ftp>cd
You must "open" a connection first
ftp>lcd C\sample
Couldnt not change local directory. No such file or directory 
ftp>get lance.c>>NUMBYTES
You must "open" a connection first 
ftp>quit
FTP done
+date+%s
date+%s: No such file or directory
+END=
+-
-: No such file or directory
+DIFF= 
+THROUGHPUT= NUMBYTES/DIFF
./ftp.sh: NUMBYTES/DIFF No such file or directory
+exit 0 

Hi all,
In the below script to download file names with todays date from ftp, how can i delete the file downloaded from the ftp site after sucessfully downloading the same. I am using the below script however, its not deleting after download of the file.

#!/bin/bash -vx
now_date=`date +%d%m20%y`
ftp -in 192.168.77.7<<END_SCRIPT
quote USER abc
quote PASS XXXX
bin
prompt off
cd /PC65021001 --folder on ftp
lcd /report/common/scripttesting/FTP_down --folder on local drive
mget PC65021001-${now_date}-*
mdel PC65021001-${now_date}-*
bye
END_SCRIPT

itsviju,

Don't hijack threads and no duplicate or cross-posting, read the rules.

Regards

Yes mandhan,

The space will not be there after "=" sign.

Regards,
MPS