Name: Leslie Date: September 3, 2002 at 01:18:15 Pacific Subject: Remote directory for FTP
Comment:
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.
Example :
If condition A remote_dir = A elseif condition B remote_dir = B elseif condition C remote_dir = C else remote_dir = D endif
How do I do this ?? Can I pass in a variable from the shell script to the FTP script ??
Sorry, but they are actually in the same script. The script goes something like this:
# 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
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 ??
Instead of redirecting the standard input (/tmp/tmp.ftp echo "password">>/tmp/tmp.ftp echo "lcd local_directory">>/tmp/tmp.ftp echo "cd $1">/tmp/tmp.ftp echo "... and then, inside your script: ftp -n -v -i servername > Logfile Hope this could help you...
I'm currently writing something similar to this. What I've done is written some code that obtains a list of directories from the remote server, gets a list of files from those directories then transfers them via ftp.
Once I have the list of directories and files, my code then creates an FTP command file that has the directory to change to and the files to get (our could use mget). This way I don't need to know the directories on the remote server till the code runs and it finds the directories it self.
eg ftp -iv host < ftp.cmd {This runs the ftp.cmd file on the remote server.)
Please feel free to contact me if you wish to discuss this further.