- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl Net::FTP and ls
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 06:25 AM
11-16-2005 06:25 AM
exec the "exec" below when the $file is not
present with "ls". It just passes through.
This is only when connecting to another server
that returns ftp error code 552(vax) not 550
as with hp to hp.
$ftp->ls ($file) or die (exec "$pager $pageid \"No file. \"") ;
So how do you tell perl that code 552 is an
error so die and exec?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 08:13 AM
11-16-2005 08:13 AM
SolutionI would do it something like this:
use Net::FTP;
use English;
use constant OKEY_DOKEY => 2;
...
...
# Wildcards will work so it's a good idea
# to load an array
my $Pattern = "*.txt";
my @tmp_array = ftp->ls($Pattern);
my $stat = ftp->status;
my $cc = 0;
if ($stat == OKEY_DOKEY)
{
my $i = 0;
while ($i <= $#tmp_array)
{
printf("%s\n",$tmp_array[$i]);
++$i;
}
}
else
{
$cc = ($stat != 0) ? $stat : 243;
printf STDERR
("ls of '%s' failed; (%d)\",$Pattern,
$cc);
}
ftp->quit;
exit($cc);
----------------------------------------
I will be the first to admit that my Perl tends to be a bit wordy but I never have to ask myself 6 months later "Now what does this do?".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 08:43 AM
11-16-2005 08:43 AM
Re: Perl Net::FTP and ls
If I understand correctly. There is a
way to get the status(error code) after
the ls that I am doing and check that
code number. The syntax eludes me though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 09:21 AM
11-16-2005 09:21 AM
Re: Perl Net::FTP and ls
@tmp_array = $ftp->ls($file);
you can check the status of that ls by examining $ftp->status
(the most significant digit only) or
by examining $ftp->code (all 3 digits).
Generally all you care oabout is the most significant digit and '2' means that all is well with the most recently executed function (get,put,cd,ls,binary,ascii, ...).
my @tmp_array = $ftp->ls("*.txt");
my $cmd_status = $ftp->status;
if ($cmd_status == 2)
{
# all is well
# do whatever with the elements of @tmp_array
}
else
{
# bad
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2005 12:57 AM
11-17-2005 12:57 AM
Re: Perl Net::FTP and ls
return code of 5xx is considered some type
of failure and checking with "status" gives
back from return code 552 just 5 is
sufficent to determine that there is some
failure. Although I found that "code"
returns the full code 552.
Thanks again Clay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2005 01:03 AM
11-17-2005 01:03 AM
Re: Perl Net::FTP and ls
Your nterpretation that it is sufficient to only check the first digit of the 'ftp' return code is correct.
The first digit indicates whether the reply is good, bad, or incomplete (e.g. 5=not accepted).
The second digit indicates the functional area (e.g. 5=file system related information).
The third digit simply provides further clarification.
See the man pages for 'ftpd(1M)' for more information.
Regards!
...JRF...