Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2002
    Posts
    2

    Unanswered: Automatic FTP using mput

    Hi,
    I have written an automated FTP script for mput (ie. to put many files from a local to a remote host). However, I will only know the remote directory during run-time.

    # Check for condition.

    If condition A
    $1 = A
    elseif condition B
    $1 = B
    elseif condition C
    $1 = C
    else
    $1 = D
    endif

    # FTP Scripts
    ftp -n -v -i servername > Logfile < user username password

    lcd local_directory

    cd $1

    ascii

    mput *

    quit

    EOF


    The script works fine except that my files were ftp to the root of the reomote host rather than the remote directory, $1

    It seems that $1 did not take the value of the If condition statement above. Can I pass in the value of $1 from the condition script to the FTP script ??


    Thank You.

  2. #2
    Join Date
    Aug 2002
    Location
    UK
    Posts
    87
    I think you can pass the directory name but it sould be in the form
    cd ./$1 (cd ./<remote host directory>)

  3. #3
    Join Date
    Sep 2002
    Posts
    2

    Unhappy Define variables in FTP

    Nope.. cd ./$1 did not work. It gave me the error message :

    CWD .$1
    550 .$1: The system cannot find the file specified.

    I've read that $ has been used as a reserved symbol to run a macro.

    $ macroname

    How can we define variables in an FTP script ??

  4. #4
    Join Date
    Aug 2002
    Location
    UK
    Posts
    87
    Humm.... It works ok for me. I'm running on Sun Solaris. What unix version are you using ??

    $1 is the script reference to the first value after the script name in the command line.

    I.E. ./MyFtpScript.sh MyDirectory

    script variables within the script still use the '$' symbol but have the name that was first used

    I.E MyVariable=/usr/home/location

    cd ${MyVariable}

  5. #5
    Join Date
    Aug 2002
    Location
    UK
    Posts
    87
    So any luck yet Leslie ?
    Last edited by WingMan; 10-22-02 at 08:23.

  6. #6
    Join Date
    Oct 2002
    Posts
    1

    Post

    Hello,

    Here is one way of automating FTP seesion.


    #!/bin/ksh

    REM_USER=user
    REM_PASS=pass

    {
    echo "open remote_host"
    echo "user $REM_USER $REM_PASS"

    #-- Following code will allow selecting remote dir as run time.
    if [ condition1 ] ; then
    echo "cd A"
    elif [ condition2 ] ; then
    echo "cd B"
    else
    echo "cd C"
    fi

    echo "put local_file remote_file"
    echo "bye"
    } | ftp -vin

    # end of file #

    Ramesh

  7. #7
    Join Date
    Nov 2003
    Location
    Chicago
    Posts
    3

    Smile Thank You

    I found your reply useful Thanks...

  8. #8
    Join Date
    Dec 2002
    Posts
    104

    Re: Automatic FTP using mput

    Originally posted by Leslie
    Hi,
    I have written an automated FTP script for mput (ie. to put many files from a local to a remote host). However, I will only know the remote directory during run-time.

    # Check for condition.

    If condition A
    $1 = A
    elseif condition B
    $1 = B
    elseif condition C
    $1 = C
    else
    $1 = D
    endif

    # FTP Scripts
    ftp -n -v -i servername > Logfile < user username password

    lcd local_directory

    cd $1

    ascii

    mput *

    quit

    EOF


    The script works fine except that my files were ftp to the root of the reomote host rather than the remote directory, $1

    It seems that $1 did not take the value of the If condition statement above. Can I pass in the value of $1 from the condition script to the FTP script ??


    Thank You.
    hi leslie!

    juat a thought.....is there a space on either side of equal to sign while assigning value to $1

    like : the code u gave above contains space $1 = D
    it shud be $1=D

    --Pooja

  9. #9
    Join Date
    Mar 2011
    Posts
    1

    Hi

    Pooja,

    I hope this simple FTP command will help you...

    step 1:
    copy below script to notepad and save in C drive as "deploy.txt" in your local computer..
    and edit the script giving valid paths with login credentials...

    username
    password
    cd "Remote FTP directory"
    mput D:\SourceCode\*
    bye

    step 2:

    copy below script to note pad and save it .bat extention on your local computer..
    you need to add your IP address


    ftp -i -s:c:\deploy.ftp IPAddress






    Quote Originally Posted by pooja View Post
    hi leslie!

    juat a thought.....is there a space on either side of equal to sign while assigning value to $1

    like : the code u gave above contains space $1 = D
    it shud be $1=D

    --Pooja

  10. #10
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink

    Unix?
    Better try something like this:
    Code:
    #... Etc ...
    # Check for condition.
    condition=$1
    case  $condition in
      A) TGTDIR='/Mydir/A';;
      B) TGTDIR='/Mydir/B';;
      C) TGTDIR='/Mydir/C';;
      *) TGTDIR='/Mydir/D';;
    esac
    
    # FTP Scripts
    ftp -n -v -i $servername > Logfile < user username password
    lcd local_directory
    cd $TGTDIR
    ascii
    mput *
    bye
    EOF
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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