If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > ftp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-04, 10:10
mvillan mvillan is offline
Registered User
 
Join Date: Dec 2003
Location: Ogden Utah
Posts: 34
Red face ftp

Hello:

What would be some of your suggestion if the objective is to log on to an ftp server count the number files ..... mget * the files and bring them to the local directory and count the number of files transferred to the local directory and make sure they

Originally I thought that by using the `ls |wc -l` substiution and placing to a variable and calling that variable during the ftp session would do it but I get an unrecognizable command error. Then I thought that if I did a Filecount(){
ls | wc -l
}

and then declaring the Filecount function within the ftp session would do it but it did not work.

Does any one have any suggestions or has had this experience in the past.


#!/usr/bin/sh


#####Login Variables and ip access

HOST=XXXXXXX
ID=XXXXXX
PSW=XXXXXX

#####Communication varibles for ftp logs

COMDIR=/history/comm_logs/ezlnk_ftp

#####Date Variable

DTTM=`date +%Y%m%d-%H%M`

#####
DROP_COUNT=`ls | wc -l`
PKUP_COUNT=`ls | wc -l`

###want to compare the vairables PKUP_COUNT against DROP_COUNT and if they match continue with the execution of the scrip

ftp -inv <<EOF > $COMDIR/ezlnk_out.$DTTM
open $HOST
user $ID $PSW
prompt
binary
ls
bye
EOF
__________________
mvilla
Reply With Quote
  #2 (permalink)  
Old 04-07-04, 11:09
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
If you want to get the count of files in the remote directory, you can do something like this :
Code:
Remote_count_file=tmp/ftp_ls.$$
rm -f $lsfile

ftp <<EOF_FTP
open $HOST
user $ID $PSW
prompt
ls . $Remote_count_file
bye
EOF

if [ -f $Remote_count_file ]
   then Remote_count=`wc -l <$Remote_count_file | awk '{print $1}'`
   else Remote_count=0
fi
rm -f $Remote_count_file
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 04-07-04, 11:53
mvillan mvillan is offline
Registered User
 
Join Date: Dec 2003
Location: Ogden Utah
Posts: 34
Talking ftp

Hi thank you for the quick reply ....looks awsome! Can you explain to me your train of thought? for each statement/variable.
__________________
mvilla
Reply With Quote
  #4 (permalink)  
Old 04-07-04, 13:45
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
The list of remote files is witten in a local file. The number of lines of this result file is the remote files count.

Remote_count_file=tmp/ftp_ls.$$
Name of the local file where the list of remote files will be written ($$ rpresent the pid of the process).

rm -f $Remote_count_file
Delete the result file if already exists (variable name error in the original post)

ls . $Remote_count_file
List the files in the remote directory and writes the result in the local file $Remote_count_file (I hope that this syntax is not specific to my AIX system). If the remote directory is empty, the result file is not created.

if [ -f $Remote_count_file ]
Test if the result file exists

then Remote_count=`wc -l <$Remote_count_file | awk '{print $1}'`
The result file exists and contains the list of remote files. The number of lines is the remote file count (the '<' before the file name in the wc command may be omited)

else Remote_count=0
The result file doesn't exist, the remote directory is empty (or ftp error, not checked...)
__________________
Jean-Pierre.
Reply With Quote
  #5 (permalink)  
Old 04-07-04, 14:05
mvillan mvillan is offline
Registered User
 
Join Date: Dec 2003
Location: Ogden Utah
Posts: 34
Talking THANK YOU!!!

Yeepee!!!! your syntax works excellent!!!! HuGe HelP!!

(I hope that this syntax is not specific to my AIX system)


Regards,
Milenko
__________________
mvilla
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On