PDA

View Full Version : Automatic FTP using mput


Leslie
09-04-02, 06:47
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.

WingMan
09-04-02, 08:07
I think you can pass the directory name but it sould be in the form
cd ./$1 (cd ./<remote host directory>)

Leslie
09-05-02, 03:40
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 ??

WingMan
09-06-02, 09:10
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}

WingMan
09-19-02, 11:55
So any luck yet Leslie ?

RameshP
10-10-02, 14:40
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

sjreese
11-07-03, 17:22
I found your reply useful Thanks...

pooja
11-11-03, 13:26
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