A ftp script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A ftp script
# 1  
Old 06-19-2008
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.


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

# 2  
Old 06-19-2008
Check the value of $HOST

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.

Code:
#!/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
".
# 3  
Old 06-20-2008
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

Code:
+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

# 4  
Old 06-20-2008
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,
MPSSmilie
# 5  
Old 06-20-2008
Quote:
USER= 'dragon'
PASSWD= 'dragon'
no space after '=' and quote
# 6  
Old 06-20-2008
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:
Code:
+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

# 7  
Old 06-21-2008
FTP Script

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

configuration for ftp script in main script

Hi, I am new to shell scripting,and i was planning to write a script that will FTP files to destination folder. I was planning that All configuration should be done through a properties files. and finally the output should be Files are transferred I have developed a properties file named... (4 Replies)
Discussion started by: rahul125
4 Replies

2. Shell Programming and Scripting

Need help in ftp script

hello , I am working on a FTP script which navigates to specific directory and pulls the file Issue which i am facing :: ---------------------------- i) When there is a file it pulls the file , but when there is not file in the directory it fails in the same statement and it is not... (3 Replies)
Discussion started by: ranga27
3 Replies

3. Linux

Need SCP script equivalent to FTP script .

Hi, Currently i'm using the folllowing FTP acript and its working. echo "open $server" > ftp_file echo "user $user $password" >> ftp_file echo "cd $remote_dir" >> ftp_file echo "lcd $local_dir" >> ftp_file echo "put $file">> ftp_file echo "bye" >> ftp_file ftp -nv < ftp_file I've... (1 Reply)
Discussion started by: vickramshetty
1 Replies

4. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

5. Shell Programming and Scripting

passing parameter to ftp script from output of another ftp

Hi, I have a ftp script which first gets all the file names and echo's the latest file. I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is > Rename Temp File calloc:ICMP... (5 Replies)
Discussion started by: ammu
5 Replies

6. Shell Programming and Scripting

ftp script not able to connect to ftp server.

I have the following ftp script to get files from a remote location. However, on running the script I find that I am not even able to connect to ftp server. I am able to connect to ftp server using other GUI ftp tools like WS_FTP using the same IP. IP used here is a dummy IP. What can go... (3 Replies)
Discussion started by: gram77
3 Replies

7. Shell Programming and Scripting

FTP script to FTP file to UNIX - Solaris

Hello, A couple of times per week, i receive emails notifications when files are available for processing. Currently i read these eamails with a java program and store the attachement on my C: drive and would now like to generate a PC script to send this file name up to UNIX-Solaris and... (3 Replies)
Discussion started by: bobk544
3 Replies

8. Shell Programming and Scripting

Need help - script for ftp..

I have my ftp script as below.. This is logging the messages into ftp.log file , But I want the same output(what ever messages are going into ftp.log) to be printed on the console too for the user to show the status.. Tried with "tee" .. unable to get the solution.. Can some one help me... (3 Replies)
Discussion started by: Srini75
3 Replies

9. UNIX for Dummies Questions & Answers

excuting a shell script within ftp script

Novice here... I need help with excuting a shell script on a flat file that I've transfered over from a Windows XP machine for manipulation through an auto FTP script... so that after it is transfers it excutes the shell script and then returns it back to XP machine... Any ideas... (2 Replies)
Discussion started by: Gerry405
2 Replies

10. Shell Programming and Scripting

FTP script in Unix shell script

Hello , I am trying to make a shell script (Unix) for a ftp connection to another server and to get a file. So I have no knowledge about ftp and my script must do automaticly the connection with the user and passwd. Can you help us about that... Christian... (2 Replies)
Discussion started by: steiner
2 Replies
Login or Register to Ask a Question