1830214 Members
1513 Online
109999 Solutions
New Discussion

Pass a variable via ftp

 
SOLVED
Go to solution
Dave La Mar
Honored Contributor

Pass a variable via ftp

I would like to be able to pass a variable from our mainframe to a hp-ux 11.0 script via ftp.
I have passed variables from hp-ux to the mainframe, but not the other way around.
Of course I could call a scipt to pass a variable on a fixed basis, but I would rather not have to code multiple scipts just to cover all the possible values for the variable.
Thanks for any input.
dl
"I'm not dumb. I just have a command of thoroughly useless information."
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Pass a variable via ftp

Hi Dave:

My answer to this would be to write a script to
write an FTP script.

I don't know if Perl is available on your mainframe but that would be my weapon of choice; you also get FTP error checking free of charge. Of course, you can reverse the sense of the operations and let HP-UX do a put or get as needed.


In the past, I used to do this stuff in the shell but now I NEVER do because I have found a much cleaner way to do it that makes error trapping duck soup. Do this stuff in Perl using the Net::FTP module which is available from http://www.cpan.org .

Here's how simple it can be:

#!/usr/bin/perl -w

use English;
use Net::FTP;
use strict;

my $ftp = Net::FTP->new("remotehost",Debug => 0);
$ftp->login("cstephen","top_secret");
$ftp->cwd("/tmp");
$ftp->get("myfile");
my $stat = $ftp->status;
my $full_stat = $ftp->code;
# $stat contains the first digit; usually all
# that you need to do is test if it is equal
# to 2. $full_stat contains the full 3-digit
# value but is seldom needed
printf("Status: %d Full Status: %d\n",$stat,$full_stat);
# Sample Test
if ($stat == 2)
{
print "Get was good\n";
}
else
{
print "Get was bad\n";
}
$ftp->quit;

In the above example, suppose that we wanted to replace the hard-coded "myfile" with a value
determined at run time by reading the command line.

my $filename = $ARGV[0];
shift;

We then replace the "myfile" with the variable and we are done.
$ftp->get($filename);

Notice that this method easily handles the error checking. If you like, you can use the shell for most of your script and simply use a bit a perl for the actual FTP transfers. In that case add the statement exit($stat) to the perl script and then your shell script does have a valid status indication.

Regards, Clay
If it ain't broke, I can fix that.
Dave La Mar
Honored Contributor

Re: Pass a variable via ftp

Clay -
First let me say I would give you a 10 right now, just for the info you passed, if it didn't indicate the question was resolved. So hold on.
No, perl is not available from the mainframe.
What I need to do is pass a date mmddyy to a unix script that could be most any date.
I can call a script easily enough or have a script get a file from the mainframe but I realy only want to call the unix script and pass a given date.
Thanks.
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Joseph C. Denman
Honored Contributor

Re: Pass a variable via ftp

Dave,

Are you attempting to get a file with a certain date name??


echo "Enter date file name: \c"
read "name"

ftp -i -n <open ftp.mainframe.com
user joe password
ascii
get ${name}
by
EOF

?????


Hope this helps

...jcd...
If I had only read the instructions first??
Dave La Mar
Honored Contributor

Re: Pass a variable via ftp

Thanks Joseph.
I have no problem in the area you mention.
I need to
ftp "unix_box"
username
passwd
"Pass_variable" >> unix_script

Thanks for the input though.
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Joseph C. Denman
Honored Contributor

Re: Pass a variable via ftp

Dave,

Sorry, I miss read.

The only way I can think of with ftp would be to append.

Create a file on the mainframe with the variable.

ftp unix.box
joe
password
as
append main.file unix.script
by

?????
I know nothing of mainframe, so Hope this helps.

...jcd...
If I had only read the instructions first??
A. Clay Stephenson
Acclaimed Contributor

Re: Pass a variable via ftp

Okay Dave:

Since you didn't mention what OS your mainframe is running, I don't know how to script what you describe. Plan B. Set up a cronjob on the UNIX to periodically ftp to the mainframes (using Perl, of course) and look for the presense of a parameter file. If it's there get the file otherwise simply exit. If the paramter file was found, use it to build the script to get the real data.

If it ain't broke, I can fix that.
Dave La Mar
Honored Contributor

Re: Pass a variable via ftp

Thanks Clay.
The OS is VM/VSE.
I'm moving in the direction you describe.
I can create a file with the
required variable and then insert this in the unix script using another script.
Unfortunately, this is not as clean as just passing the variable.
Scanning VSE for a file would
not be as viable as simply sending the variable at the time I want VSE to execute the unix script. (Execution of the script is dependent upon completion of a VSE job.)
Still Plugging in there.

This looks like a good one.
Will close out when I get something satisfactory to work
and pass on the results.
Thanks for all the input.
d
"I'm not dumb. I just have a command of thoroughly useless information."
Wodisch
Honored Contributor

Re: Pass a variable via ftp

Hello Dave,

even the ftp-client on your OS should have something like the ".netrc" feature, i.e. a to automate some actions (even M$ has it ;-).
Check your documentation for "netrc" or such...
Then you could create that file containing whatever you want immediately before calling "ftp"...

HTH,
Wodisch
Dave La Mar
Honored Contributor

Re: Pass a variable via ftp

Ok people -
Here's what I have settled on:
1. Create a sequential file on the mainframe containing the date needed.
2. Send the file from mainframe to unix.
3. Unix executable script reads into a variable the contents of the file sent from the mainframe.

Not the cleanest I would want, but slightly liveable.

Thanks for all the great input.

dl
"I'm not dumb. I just have a command of thoroughly useless information."