Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2004
    Posts
    5

    Exclamation Unanswered: Automation Of FTP

    How to automate an FTP session through shell script.

    The ftp site name, user name, password has to be user defined during run time, not to be given in shell script.

    Can anyone tell me how to do this in shell script.

  2. #2
    Join Date
    Feb 2004
    Posts
    143

    Re: Automation Of FTP

    #Try this ----


    echo "Enter ftp user name"
    read FTPUSER
    echo "Enter ftp user password"
    read FTPPASS
    echo "Enter destination server"
    read FTPSERVER
    echo "Enter file to transfer"
    read FTPFILE
    ftp -n $FTPSERVER <<END_SCRIPT
    user $FTPUSER $FTPPASS
    put $FTPFILE
    quit
    END_SCRIPT
    exit 0

  3. #3
    Join Date
    Feb 2004
    Posts
    143

    Re: Automation Of FTP

    I thought of removing the line
    exit 0
    before posting it here but forgot. ( Remove the line if you don't want to exit out of your user session after running the script )

  4. #4
    Join Date
    Mar 2004
    Posts
    5

    Exclamation Re: Automation Of FTP

    Hi,

    It is working fine.

    I need some more clarification.

    I want to connect to a ftp server and on the ftp server i want to check for the availability of a file.

    How to do this in a shell script.

    As per your help I am able to connect to the ftp site by getting user password & server details from user. Can I also mention the file to search in the ftp server along with these during run time.

    I tried, but it is not working. Can you pls help me

    Regards,
    R.Ramesh.

  5. #5
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Hi, try this

    FTP_USER="guest"
    FTP_PASS="guest"
    REMOTE_SERV="cd000000"
    REMOTE_PATH="/usr/guest/bin"
    REMOTE_SEARCH_FILE="Hello.txt"
    REMOTE_CMD="ls "$MY_FILE
    LOCAL_LOG_FILE="/tmp/MY_FTP_SCRIPT.LOG"
    > $LOCAL_LOG_FILE

    #start ftp
    ftp -n $REMOTE_SERV <<-! 2>&1 | tee -i -a $LOCAL_LOG_FILE | grep -i $REMOTE_SEARCH_FILE > /dev/null 2>&1
    user $FTP_USER $FTP_PASS
    cd $REMOTE_PATH
    $REMOTE_CMD
    bye
    !

    GREP_RESULT="$?"

    if [ "$GREP_RESULT" = "0" ]
    then
    echo "file "$REMOTE_SEARCH_FILE" found"
    else
    echo "file "$REMOTE_SEARCH_FILE" not found"
    fi
    Greetings from germany
    Peter F.

  6. #6
    Join Date
    Mar 2004
    Posts
    5

    Exclamation FTP Automation

    Hi,

    The file search code is not giving any error, the shell script is working fine during run time.

    But the problem is what ever file name i give for search, it is saying file found.

    I am not getting the code. Can you kindly explain me.

  7. #7
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    First :
    there is a little bug in my code.

    change REMOTE_CMD="ls "$MY_FILE
    to REMOTE_CMD="ls "$REMOTE_SEARCH_FILE

    Second:
    If the script does not still work, look at the LOCAL_LOG_FILE and give
    me a hardcopy of it in case the file surely exist and one when the file surely not exist. May be we do it by another way.
    Greetings from germany
    Peter F.

  8. #8
    Join Date
    Mar 2004
    Posts
    5

    Exclamation FTP Automation

    Hi,

    The shell script is not giving the correct output, even the file is not exist it is giving file found. in the local log file in the very first line it is saying ?invalid command and then the listing of the files in the ftp server.

    Can you pls help me, what went wrong.


    Regards,
    R.Ramesh.

  9. #9
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Hi,
    we are near by.
    Try this :

    FTP_USER="guest"
    FTP_PASS="guest"
    REMOTE_SERV="cd000000"
    REMOTE_PATH="/usr/guest/bin"
    REMOTE_SEARCH_FILE="hallo3"
    REMOTE_CMD="ls"
    LOCAL_LOG_FILE="/tmp/MY_FTP_SCRIPT.LOG"
    > $LOCAL_LOG_FILE

    # FTP starten
    ftp -n $REMOTE_SERV <<-! 2>&1 | tee -i -a $LOCAL_LOG_FILE > /dev/null 2>&1
    user $FTP_USER $FTP_PASS
    cd $REMOTE_PATH
    $REMOTE_CMD
    bye
    !
    GREP_RESULT=`grep $REMOTE_SEARCH_FILE $LOCAL_LOG_FILE`
    if [ -n "$GREP_RESULT" ]
    then
    echo "file ==> "$REMOTE_SEARCH_FILE" found"
    else
    echo "file ==> "$REMOTE_SEARCH_FILE" not found"
    fi
    echo "."
    echo "------------ Output from LOCAL_LOG_FILE ---------"
    cat $LOCAL_LOG_FILE | pg
    Greetings from germany
    Peter F.

  10. #10
    Join Date
    Oct 2004
    Posts
    2

    I am not able to get the output from the code plz help me out

    Hello !


    I am also trying to connect to a remote system and get the file by FTP but after getting the file i am unable to do grep in that same file which is downloaded to the path where i have load the program run the FTP of the file.



    With regards,

    Madhushree

Posting Permissions

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