1833747 Members
2484 Online
110063 Solutions
New Discussion

FTP shell script needed

 
Rajkumar_3
Regular Advisor

FTP shell script needed

Dear All,

We were having two HP L3000 servers "vmtac1" & "vmtac2" which are the host names of the two servers.I want to FTP files from "vmtac1" to "vmtac2" from a perticular directory from one server to another server.I want to place the directory path & names in the ".txt" file and another shell script which will read the directories from the ".txt" file and FTP the files from "vmtac1" to "vmtac2" servers.I have written a shell script but it was not reliable because i was not much experienced in the unix shell scripting.Can any one can provide the script.BUt for each and every file i want to use "wait" clause and if any error occurs it to through the error to the "/utf001/dac/out" directory and that script has to through some message once its successfull.

The text file looks like "utf001.txt" which contains as below /utf001/dac/in. That means i want to copy the files from the "./in" directory to another server as mentioned above.The directory stucture as same as in the two servers.The main reason of reading the text file is i dont want to hardcode the dorectory path and name in the shell script.If want to change the directory name i can simple change it in the text file.

Thanks for the advance in help.

Raj
Oracle DBA
10 REPLIES 10
Rajkumar_3
Regular Advisor

Re: FTP shell script needed

Dear all,

This is the shell script like below but it dosent rearch for any file.is it possible to pass any $parameter in the "lcd" or "cd" at the ftp prompt.??

ftp -n 00.000.000.00 <user username password
lcd
cd
mput *
quit
EOF

How can i read directory path from the text file in the local as well as remote system?

Please correct me if i am wrong.thanks.

raj
Oracle DBA
John Poff
Honored Contributor

Re: FTP shell script needed

Hi,

I think you'll need to write a script that reads your text file to get the local and remote directories, and then build the actual ftp script to be executed.

JP
Ramkumar Devanathan
Honored Contributor

Re: FTP shell script needed

Raj,

You may use wget - i am trying to build it on my 11.0 box - i have some issues but i definitely think it can be built.

thereafter, you may run it as follows -
wget --proxy=off --input-file=

in the filename placeholder above, you would specify utf001.txt.

it auto-resumes ftp transfers, in case any error occurs. in fact, you can create bookmarks for particular directory's on the ftp host.

instead of at ftp prompt, typing cd /abc/def/ghi, you may create a bookmark for hostname:/abc/def/ghi as say abcd and say at the ftp prompt open abcd - it has an option of storing or not storing the password and login details.

hope this helps.

- ramd.
HPE Software Rocks!
Ramkumar Devanathan
Honored Contributor

Re: FTP shell script needed

Raj,

command requires the ftp hostname as a last arg...

wget --proxy=off --input-file= host

Ignore the line about bookmarks in my previous post - coz it is not right. bookmarks are available with ncftp - not wget.

wget is used for recursive downloads of entire directory structures, while ncftp is an advanced interactive ftp client.

- ramd.
HPE Software Rocks!
Steven E. Protter
Exalted Contributor

Re: FTP shell script needed

Allow me to propose an alaternate solution, though I know this is annoying.

Install this on both boxes:

Secure shell
http://www.software.hp.com/cgi-bin/swdepot_parser.cgi/cgi/displayProductInfo.pl?productNumber=T1471AA


Follow the attached box and you will be able to use the scp command to copy stuff back and forth with no trouble at all. Plus you won't have to hard code passwords into your ftp scripts.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Emerson Valley
Occasional Advisor

Re: FTP shell script needed

Raj, have you considered using the remote copy command?

rcp -r /path/directory vmtac2:/path/directory

or

rcp -r vntac1:/path/directory /path/directory

the first commands assumes you are running the script on vmtac1 the second on vmtac2, Or you can even specify both servers in your command line and run it from any machine.

-Emerson
Colin Topliss
Esteemed Contributor

Re: FTP shell script needed

If you want to do error trapping, you could look at using either expect (NOT my most favourite utility), or Perl and the Net::FTP module (which I love using).

I've written huge applications which use Net::FTP - alot more robust than Expect, and infinitely more flexible than just using shell.
Colin Topliss
Esteemed Contributor

Re: FTP shell script needed

Heres a very quick Perl example:

#!/opt/perl/bin/perl

use English;
use Env;
use Net::FTP;

$host="disney";
$user_name="micky";
$user_password="mouse";
$dest_dir="/tmp";
$file_name="*.tar";

# Create the connection
$ftp=Net::FTP->new($host,debug =>1) or die ("Unable to make connection\n");

# Login
$ftp->login($user_name,$user_password) or die ("Unable to log in\n");

# This is how to assign a return code
$return_code=($ftp->cwd($dest_dir));
# This is where you could check your return code for failure

# Read the commands contents into an array
@file_list=$ftp->ls ($file_name);

# Quit the session
$ftp->quit;

# Process the array - this example just prints it out
foreach (@file_list)
{
print "$_\n";
}



You can make this as complex as you'd like!

Col
RolandH
Honored Contributor

Re: FTP shell script needed

The easiest way I think will be to using cpio.
How I have understand your problem. The users on both machine are the same and the directories and files are the same, right ?!

Ok, use this from your local machine to the remote machine

find . -print |cpio -pvumod |remsh " cd /; cpio -pumid"

First of all you have to go to the directory from which you want have all sub-dirs to the remote machine and then use the commando I've mentioned above.


Roland

Sometimes you lose and sometimes the others win