Results 1 to 5 of 5

Thread: ftp

  1. #1
    Join Date
    Dec 2003
    Location
    Ogden Utah
    Posts
    34

    Red face Unanswered: 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

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

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

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •