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 > Automatic FTP using mput

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-04-02, 05:47
Leslie Leslie is offline
Registered User
 
Join Date: Sep 2002
Posts: 2
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.
Reply With Quote
  #2 (permalink)  
Old 09-04-02, 07:07
WingMan WingMan is offline
Registered User
 
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>)
Reply With Quote
  #3 (permalink)  
Old 09-05-02, 02:40
Leslie Leslie is offline
Registered User
 
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 ??
Reply With Quote
  #4 (permalink)  
Old 09-06-02, 08:10
WingMan WingMan is offline
Registered User
 
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}
Reply With Quote
  #5 (permalink)  
Old 09-19-02, 10:55
WingMan WingMan is offline
Registered User
 
Join Date: Aug 2002
Location: UK
Posts: 87
So any luck yet Leslie ?

Last edited by WingMan; 10-22-02 at 07:23.
Reply With Quote
  #6 (permalink)  
Old 10-10-02, 13:40
RameshP RameshP is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 11-07-03, 16:22
sjreese sjreese is offline
Registered User
 
Join Date: Nov 2003
Location: Chicago
Posts: 3
Smile Thank You

I found your reply useful Thanks...
Reply With Quote
  #8 (permalink)  
Old 11-11-03, 12:26
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
Re: Automatic FTP using mput

Quote:
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
Reply With Quote
  #9 (permalink)  
Old 03-22-11, 08:07
manjunathb manjunathb is offline
Registered User
 
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
Reply With Quote
  #10 (permalink)  
Old 03-22-11, 14:30
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
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
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