Manual Pages for UNIX Darwin command on man Net::libnetFAQ
MyWebUniversity

Manual Pages for UNIX Darwin command on man Net::libnetFAQ

Net::libnetFAQ(3pm) Perl Programmers Reference Guide Net::libnetFAQ(3pm)

NAME

libnetFAQ - libnet Frequently Asked Questions

DESCRIPTION

WWhheerree ttoo ggeett tthhiiss ddooccuummeenntt This document is distributed with the libnet distribution, and is also available on the libnet web page at http://search.cpan.org/~gbarr/libnet/ HHooww ttoo ccoonnttrriibbuuttee ttoo tthhiiss ddooccuummeenntt You may mail corrections, additions, and suggestions to me gbarr@pobox.com. AAuutthhoorr aanndd CCooppyyrriigghhtt IInnffoorrmmaattiioonn

Copyright (c) 1997-1998 Graham Barr. All rights reserved. This docu-

ment is free; you can redistribute it and/or modify it under the terms of the Artistic License. DDiissccllaaiimmeerr This information is offered in good faith and in the hope that it may be of use, but is not guaranteed to be correct, up to date, or suitable for any particular purpose whatsoever. The authors accept no liability in respect of this information or its use. OObbttaaiinniinngg aanndd iinnssttaalllliinngg lliibbnneett WWhhaatt iiss lliibbnneett ?? libnet is a collection of perl5 modules which all related to network programming. The majority of the modules available provided the client

side of popular server-client protocols that are used in the internet

community. WWhhiicchh vveerrssiioonn ooff ppeerrll ddoo II nneeeedd ?? libnet has been know to work with versions of perl from 5.002 onwards. However if your release of perl is prior to perl5.004 then you will need to obtain and install the IO distribution from CPAN. If you have

perl5.004 or later then you will have the IO modules in your installa-

tion already, but CPAN may contain updates. WWhhaatt ootthheerr mmoodduulleess ddoo II nneeeedd ?? The only modules you will need installed are the modules from the IO distribution. If you have perl5.004 or later you will already have these modules. WWhhaatt mmaacchhiinneess ssuuppppoorrtt lliibbnneett ??

libnet itself is an entirely perl-code distribution so it should work

on any machine that perl runs on. However IO may not work with some machines and earlier releases of perl. But this should not be the case with perl version 5.004 or later. WWhheerree ccaann II ggeett tthhee llaatteesstt lliibbnneett rreelleeaassee The latest libnet release is always on CPAN, you will find it in

http://www.cpan.org/modules/by-module/Net/

The latest release and information is also available on the libnet web page at http://search.cpan.org/~gbarr/libnet/ UUssiinngg NNeett::::FFTTPP HHooww ddoo II ddoowwnnllooaadd ffiilleess ffrroomm aann FFTTPP sseerrvveerr ?? An example taken from an article posted to comp.lang.perl.misc

#!/your/path/to/perl

# a module making life easier

use Net::FTP;

# for debuging: $ftp = Net::FTP->new('site','Debug',10);

# open a connection and log in!

$ftp = Net::FTP->new('targetsite.somewhere.xxx');

$ftp->login('username','password');

# set transfer mode to binary

$ftp->binary();

# change the directory on the ftp site

$ftp->cwd('/some/path/to/somewhere/');

foreach $name ('file1', 'file2', 'file3') {

# get's arguments are in the following order:

# ftp server's filename

# filename to save the transfer to on the local machine

# can be simply used as get($name) if you want the same name

$ftp->get($name,$name);

}

# ftp done!

$ftp->quit;

HHooww ddoo II ttrraannssffeerr ffiilleess iinn bbiinnaarryy mmooddee ?? To transfer files without translation Net::FTP provides the "binary" method

$ftp->binary;

HHooww ccaann II ggeett tthhee ssiizzee ooff aa ffiillee oonn aa rreemmoottee FFTTPP sseerrvveerr ?? HHooww ccaann II ggeett tthhee mmooddiiffiiccaattiioonn ttiimmee ooff aa ffiillee oonn aa rreemmoottee FFTTPP sseerrvveerr ?? HHooww ccaann II cchhaannggee tthhee ppeerrmmiissssiioonnss ooff aa ffiillee oonn aa rreemmoottee sseerrvveerr ?? The FTP protocol does not have a command for changing the permissions of a file on the remote server. But some ftp servers may allow a chmod command to be issued via a SITE command, eg

$ftp->quot('site chmod 0777',$filename);

But this is not guaranteed to work. CCaann II ddoo aa rreeggeett ooppeerraattiioonn lliikkee tthhee ffttpp ccoommmmaanndd ?? HHooww ddoo II ggeett aa ddiirreeccttoorryy lliissttiinngg ffrroomm aann FFTTPP sseerrvveerr ?? CChhaannggiinngg ddiirreeccttoorryy ttoo """" ddooeess nnoott ffaaiill ??

Passing an argument of "" to ->cwd() has the same affect of calling

->cwd() without any arguments. Turn on Debug (See below) and you will

see what is happening

$ftp = Net::FTP->new($host, Debug => 1);

$ftp->login;

$ftp->cwd("");

gives Net::FTP=GLOB(0x82196d8)>>> CWD / Net::FTP=GLOB(0x82196d8)<<< 250 CWD command successful. II aamm bbeehhiinndd aa SSOOCCKKSS ffiirreewwaallll,, bbuutt tthhee FFiirreewwaallll ooppttiioonn ddooeess nnoott wwoorrkk ?? The Firewall option is only for support of one type of firewall. The type supported is an ftp proxy. To use Net::FTP, or any other module in the libnet distribution,

through a SOCKS firewall you must create a socks-ified perl executable

by compiling perl with the socks library. II aamm bbeehhiinndd aann FFTTPP pprrooxxyy ffiirreewwaallll,, bbuutt ccaannnnoott aacccceessss mmaacchhiinneess oouuttssiiddee ?? Net::FTP implements the most popular ftp proxy firewall approach. The scheme implemented is that where you log in to the firewall with "user@hostname" I have heard of one other type of firewall which requires a login to the firewall with an account, then a second login with "user@hostname".

You can still use Net::FTP to traverse these firewalls, but a more man-

ual approach must be taken, eg

$ftp = Net::FTP->new($firewall) or die $@;

$ftp->login($firewalluser, $firewallpasswd) or die $ftp->message;

$ftp->login($extuser . '@' . $exthost, $extpasswd) or die $ftp->message.

MMyy ffttpp pprrooxxyy ffiirreewwaallll ddooeess nnoott lliisstteenn oonn ppoorrtt 2211 FTP servers usually listen on the same port number, port 21, as any other FTP server. But there is no reason why this has to be the case. If you pass a port number to Net::FTP then it assumes this is the port number of the final destination. By default Net::FTP will always try to connect to the firewall on port 21. Net::FTP uses IO::Socket to open the connection and IO::Socket allows

the port number to be specified as part of the hostname. So this prob-

lem can be resolved by either passing a Firewall option like "host-

name:1234" or by setting the "ftpfirewall" option in Net::Config to be a string in in the same form. IIss iitt ppoossssiibbllee ttoo cchhaannggee tthhee ffiillee ppeerrmmiissssiioonnss ooff aa ffiillee oonn aann FFTTPP sseerrvveerr ??

The answer to this is "maybe". The FTP protocol does not specify a com-

mand to change file permissions on a remote host. However many servers do allow you to run the chmod command via the "SITE" command. This can be done with

$ftp->site('chmod','0775',$file);

II hhaavvee sseeeenn ssccrriippttss ccaallll aa mmeetthhoodd mmeessssaaggee,, bbuutt ccaannnnoott ffiinndd iitt ddooccuu-

mmeenntteedd ?? Net::FTP, like several other packages in libnet, inherits from Net::Cmd, so all the methods described in Net::Cmd are also available on Net::FTP objects. WWhhyy ddooeess NNeett::::FFTTPP nnoott iimmpplleemmeenntt mmppuutt aanndd mmggeett mmeetthhooddss The quick answer is because they are easy to implement yourself. The

long answer is that to write these in such a way that multiple plat-

forms are supported correctly would just require too much code. Below are some examples how you can implement these yourself. sub mput {

my($ftp,$pattern) = @;

foreach my $file (glob($pattern)) {

$ftp->put($file) or warn $ftp->message;

} } sub mget {

my($ftp,$pattern) = @;

foreach my $file ($ftp->ls($pattern)) {

$ftp->get($file) or warn $ftp->message;

} } UUssiinngg NNeett::::SSMMTTPP

WWhhyy ccaann''tt tthhee ppaarrtt ooff aann EEmmaaiill aaddddrreessss aafftteerr tthhee @@ bbee uusseedd aass tthhee hhoosstt-

nnaammee ?? The part of an Email address which follows the @ is not necessarily a hostname, it is a mail domain. To find the name of a host to connect for a mail domain you need to do a DNS MX lookup WWhhyy ddooeess NNeett::::SSMMTTPP nnoott ddoo DDNNSS MMXX llooookkuuppss ?? Net::SMTP implements the SMTP protocol. The DNS MX lookup is not part of this protocol. The verify method always returns true ? Well it may seem that way, but it does not. The verify method returns true if the command succeeded. If you pass verify an address which the server would normally have to forward to another machine, the command will succeed with something like 252 Couldn't verify but will attempt delivery anyway This command will fail only if you pass it an address in a domain the server directly delivers for, and that address does not exist. DDeebbuuggggiinngg ssccrriippttss HHooww ccaann II ddeebbuugg mmyy ssccrriippttss tthhaatt uussee NNeett::::** mmoodduulleess ?? Most of the libnet client classes allow options to be passed to the constructor, in most cases one option is called "Debug". Passing this

option with a non-zero value will turn on a protocol trace, which will

be sent to STDERR. This trace can be useful to see what commands are being sent to the remote server and what responses are being received back.

#!/your/path/to/perl

use Net::FTP;

my $ftp = new Net::FTP($host, Debug => 1);

$ftp->login('gbarr','password');

$ftp->quit;

this script would output something like Net::FTP: Net::FTP(2.22) Net::FTP: Exporter Net::FTP: Net::Cmd(2.0801) Net::FTP: IO::Socket::INET Net::FTP: IO::Socket(1.1603) Net::FTP: IO::Handle(1.1504)

Net::FTP=GLOB(0x8152974)<<< 220 imagine FTP server (Version wu-2.4(5) Tue Jul 29 11:17:18 CDT 1997) ready.

Net::FTP=GLOB(0x8152974)>>> user gbarr Net::FTP=GLOB(0x8152974)<<< 331 Password required for gbarr. Net::FTP=GLOB(0x8152974)>>> PASS .... Net::FTP=GLOB(0x8152974)<<< 230 User gbarr logged in. Access restrictions apply. Net::FTP=GLOB(0x8152974)>>> QUIT Net::FTP=GLOB(0x8152974)<<< 221 Goodbye. The first few lines tell you the modules that Net::FTP uses and their versions, this is useful data to me when a user reports a bug. The last seven lines show the communication with the server. Each line has three

parts. The first part is the object itself, this is useful for separat-

ing the output if you are using multiple objects. The second part is either "<<<<" to show data coming from the server or ">>>>" to show data going to the server. The remainder of the line is the command being sent or response being received. AUTHOR AND COPYRIGHT Copyright (c) 1997 Graham Barr. All rights reserved.

$Id: //depot/libnet/Net/libnetFAQ.pod#6 $

perl v5.8.8 2001-09-21 Net::libnetFAQ(3pm)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™