1*0Sstevel@tonic-gate=head1 NAME 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gatelibnetFAQ - libnet Frequently Asked Questions 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gate=head1 DESCRIPTION 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gate=head2 Where to get this document 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gateThis document is distributed with the libnet distribution, and is also 10*0Sstevel@tonic-gateavailable on the libnet web page at 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate http://search.cpan.org/~gbarr/libnet/ 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate=head2 How to contribute to this document 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gateYou may mail corrections, additions, and suggestions to me 17*0Sstevel@tonic-gategbarr@pobox.com. 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gate=head1 Author and Copyright Information 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gateCopyright (c) 1997-1998 Graham Barr. All rights reserved. 22*0Sstevel@tonic-gateThis document is free; you can redistribute it and/or modify it 23*0Sstevel@tonic-gateunder the terms of the Artistic License. 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate=head2 Disclaimer 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gateThis information is offered in good faith and in the hope that it may 28*0Sstevel@tonic-gatebe of use, but is not guaranteed to be correct, up to date, or suitable 29*0Sstevel@tonic-gatefor any particular purpose whatsoever. The authors accept no liability 30*0Sstevel@tonic-gatein respect of this information or its use. 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate=head1 Obtaining and installing libnet 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate=head2 What is libnet ? 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gatelibnet is a collection of perl5 modules which all related to network 38*0Sstevel@tonic-gateprogramming. The majority of the modules available provided the 39*0Sstevel@tonic-gateclient side of popular server-client protocols that are used in 40*0Sstevel@tonic-gatethe internet community. 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate=head2 Which version of perl do I need ? 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gatelibnet has been know to work with versions of perl from 5.002 onwards. However 45*0Sstevel@tonic-gateif your release of perl is prior to perl5.004 then you will need to 46*0Sstevel@tonic-gateobtain and install the IO distribution from CPAN. If you have perl5.004 47*0Sstevel@tonic-gateor later then you will have the IO modules in your installation already, 48*0Sstevel@tonic-gatebut CPAN may contain updates. 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate=head2 What other modules do I need ? 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gateThe only modules you will need installed are the modules from the IO 53*0Sstevel@tonic-gatedistribution. If you have perl5.004 or later you will already have 54*0Sstevel@tonic-gatethese modules. 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate=head2 What machines support libnet ? 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gatelibnet itself is an entirely perl-code distribution so it should work 59*0Sstevel@tonic-gateon any machine that perl runs on. However IO may not work 60*0Sstevel@tonic-gatewith some machines and earlier releases of perl. But this 61*0Sstevel@tonic-gateshould not be the case with perl version 5.004 or later. 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate=head2 Where can I get the latest libnet release 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gateThe latest libnet release is always on CPAN, you will find it 66*0Sstevel@tonic-gatein 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate http://www.cpan.org/modules/by-module/Net/ 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gateThe latest release and information is also available on the libnet web page 71*0Sstevel@tonic-gateat 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate http://search.cpan.org/~gbarr/libnet/ 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate=head1 Using Net::FTP 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate=head2 How do I download files from an FTP server ? 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gateAn example taken from an article posted to comp.lang.perl.misc 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate #!/your/path/to/perl 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate # a module making life easier 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate use Net::FTP; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate # for debuging: $ftp = Net::FTP->new('site','Debug',10); 88*0Sstevel@tonic-gate # open a connection and log in! 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate $ftp = Net::FTP->new('target_site.somewhere.xxx'); 91*0Sstevel@tonic-gate $ftp->login('username','password'); 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate # set transfer mode to binary 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate $ftp->binary(); 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate # change the directory on the ftp site 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate $ftp->cwd('/some/path/to/somewhere/'); 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate foreach $name ('file1', 'file2', 'file3') { 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate # get's arguments are in the following order: 104*0Sstevel@tonic-gate # ftp server's filename 105*0Sstevel@tonic-gate # filename to save the transfer to on the local machine 106*0Sstevel@tonic-gate # can be simply used as get($name) if you want the same name 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate $ftp->get($name,$name); 109*0Sstevel@tonic-gate } 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate # ftp done! 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate $ftp->quit; 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate=head2 How do I transfer files in binary mode ? 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gateTo transfer files without <LF><CR> translation Net::FTP provides 118*0Sstevel@tonic-gatethe C<binary> method 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate $ftp->binary; 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate=head2 How can I get the size of a file on a remote FTP server ? 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate=head2 How can I get the modification time of a file on a remote FTP server ? 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate=head2 How can I change the permissions of a file on a remote server ? 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gateThe FTP protocol does not have a command for changing the permissions 129*0Sstevel@tonic-gateof a file on the remote server. But some ftp servers may allow a chmod 130*0Sstevel@tonic-gatecommand to be issued via a SITE command, eg 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate $ftp->quot('site chmod 0777',$filename); 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gateBut this is not guaranteed to work. 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate=head2 Can I do a reget operation like the ftp command ? 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate=head2 How do I get a directory listing from an FTP server ? 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate=head2 Changing directory to "" does not fail ? 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gatePassing an argument of "" to ->cwd() has the same affect of calling ->cwd() 143*0Sstevel@tonic-gatewithout any arguments. Turn on Debug (I<See below>) and you will see what is 144*0Sstevel@tonic-gatehappening 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate $ftp = Net::FTP->new($host, Debug => 1); 147*0Sstevel@tonic-gate $ftp->login; 148*0Sstevel@tonic-gate $ftp->cwd(""); 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gategives 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate Net::FTP=GLOB(0x82196d8)>>> CWD / 153*0Sstevel@tonic-gate Net::FTP=GLOB(0x82196d8)<<< 250 CWD command successful. 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate=head2 I am behind a SOCKS firewall, but the Firewall option does not work ? 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gateThe Firewall option is only for support of one type of firewall. The type 158*0Sstevel@tonic-gatesupported is an ftp proxy. 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gateTo use Net::FTP, or any other module in the libnet distribution, 161*0Sstevel@tonic-gatethrough a SOCKS firewall you must create a socks-ified perl executable 162*0Sstevel@tonic-gateby compiling perl with the socks library. 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate=head2 I am behind an FTP proxy firewall, but cannot access machines outside ? 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gateNet::FTP implements the most popular ftp proxy firewall approach. The scheme 167*0Sstevel@tonic-gateimplemented is that where you log in to the firewall with C<user@hostname> 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gateI have heard of one other type of firewall which requires a login to the 170*0Sstevel@tonic-gatefirewall with an account, then a second login with C<user@hostname>. You can 171*0Sstevel@tonic-gatestill use Net::FTP to traverse these firewalls, but a more manual approach 172*0Sstevel@tonic-gatemust be taken, eg 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate $ftp = Net::FTP->new($firewall) or die $@; 175*0Sstevel@tonic-gate $ftp->login($firewall_user, $firewall_passwd) or die $ftp->message; 176*0Sstevel@tonic-gate $ftp->login($ext_user . '@' . $ext_host, $ext_passwd) or die $ftp->message. 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate=head2 My ftp proxy firewall does not listen on port 21 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gateFTP servers usually listen on the same port number, port 21, as any other 181*0Sstevel@tonic-gateFTP server. But there is no reason why this has to be the case. 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gateIf you pass a port number to Net::FTP then it assumes this is the port 184*0Sstevel@tonic-gatenumber of the final destination. By default Net::FTP will always try 185*0Sstevel@tonic-gateto connect to the firewall on port 21. 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gateNet::FTP uses IO::Socket to open the connection and IO::Socket allows 188*0Sstevel@tonic-gatethe port number to be specified as part of the hostname. So this problem 189*0Sstevel@tonic-gatecan be resolved by either passing a Firewall option like C<"hostname:1234"> 190*0Sstevel@tonic-gateor by setting the C<ftp_firewall> option in Net::Config to be a string 191*0Sstevel@tonic-gatein in the same form. 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate=head2 Is it possible to change the file permissions of a file on an FTP server ? 194*0Sstevel@tonic-gate 195*0Sstevel@tonic-gateThe answer to this is "maybe". The FTP protocol does not specify a command to change 196*0Sstevel@tonic-gatefile permissions on a remote host. However many servers do allow you to run the 197*0Sstevel@tonic-gatechmod command via the C<SITE> command. This can be done with 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate $ftp->site('chmod','0775',$file); 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate=head2 I have seen scripts call a method message, but cannot find it documented ? 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gateNet::FTP, like several other packages in libnet, inherits from Net::Cmd, so 204*0Sstevel@tonic-gateall the methods described in Net::Cmd are also available on Net::FTP 205*0Sstevel@tonic-gateobjects. 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate=head2 Why does Net::FTP not implement mput and mget methods 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gateThe quick answer is because they are easy to implement yourself. The long 210*0Sstevel@tonic-gateanswer is that to write these in such a way that multiple platforms are 211*0Sstevel@tonic-gatesupported correctly would just require too much code. Below are 212*0Sstevel@tonic-gatesome examples how you can implement these yourself. 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gatesub mput { 215*0Sstevel@tonic-gate my($ftp,$pattern) = @_; 216*0Sstevel@tonic-gate foreach my $file (glob($pattern)) { 217*0Sstevel@tonic-gate $ftp->put($file) or warn $ftp->message; 218*0Sstevel@tonic-gate } 219*0Sstevel@tonic-gate} 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gatesub mget { 222*0Sstevel@tonic-gate my($ftp,$pattern) = @_; 223*0Sstevel@tonic-gate foreach my $file ($ftp->ls($pattern)) { 224*0Sstevel@tonic-gate $ftp->get($file) or warn $ftp->message; 225*0Sstevel@tonic-gate } 226*0Sstevel@tonic-gate} 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate=head1 Using Net::SMTP 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate=head2 Why can't the part of an Email address after the @ be used as the hostname ? 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gateThe part of an Email address which follows the @ is not necessarily a hostname, 234*0Sstevel@tonic-gateit is a mail domain. To find the name of a host to connect for a mail domain 235*0Sstevel@tonic-gateyou need to do a DNS MX lookup 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate=head2 Why does Net::SMTP not do DNS MX lookups ? 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gateNet::SMTP implements the SMTP protocol. The DNS MX lookup is not part 240*0Sstevel@tonic-gateof this protocol. 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate=head2 The verify method always returns true ? 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gateWell it may seem that way, but it does not. The verify method returns true 245*0Sstevel@tonic-gateif the command succeeded. If you pass verify an address which the 246*0Sstevel@tonic-gateserver would normally have to forward to another machine, the command 247*0Sstevel@tonic-gatewill succeed with something like 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate 252 Couldn't verify <someone@there> but will attempt delivery anyway 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gateThis command will fail only if you pass it an address in a domain 252*0Sstevel@tonic-gatethe server directly delivers for, and that address does not exist. 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate=head1 Debugging scripts 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate=head2 How can I debug my scripts that use Net::* modules ? 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gateMost of the libnet client classes allow options to be passed to the 259*0Sstevel@tonic-gateconstructor, in most cases one option is called C<Debug>. Passing 260*0Sstevel@tonic-gatethis option with a non-zero value will turn on a protocol trace, which 261*0Sstevel@tonic-gatewill be sent to STDERR. This trace can be useful to see what commands 262*0Sstevel@tonic-gateare being sent to the remote server and what responses are being 263*0Sstevel@tonic-gatereceived back. 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate #!/your/path/to/perl 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate use Net::FTP; 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gate my $ftp = new Net::FTP($host, Debug => 1); 270*0Sstevel@tonic-gate $ftp->login('gbarr','password'); 271*0Sstevel@tonic-gate $ftp->quit; 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gatethis script would output something like 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate Net::FTP: Net::FTP(2.22) 276*0Sstevel@tonic-gate Net::FTP: Exporter 277*0Sstevel@tonic-gate Net::FTP: Net::Cmd(2.0801) 278*0Sstevel@tonic-gate Net::FTP: IO::Socket::INET 279*0Sstevel@tonic-gate Net::FTP: IO::Socket(1.1603) 280*0Sstevel@tonic-gate Net::FTP: IO::Handle(1.1504) 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate Net::FTP=GLOB(0x8152974)<<< 220 imagine FTP server (Version wu-2.4(5) Tue Jul 29 11:17:18 CDT 1997) ready. 283*0Sstevel@tonic-gate Net::FTP=GLOB(0x8152974)>>> user gbarr 284*0Sstevel@tonic-gate Net::FTP=GLOB(0x8152974)<<< 331 Password required for gbarr. 285*0Sstevel@tonic-gate Net::FTP=GLOB(0x8152974)>>> PASS .... 286*0Sstevel@tonic-gate Net::FTP=GLOB(0x8152974)<<< 230 User gbarr logged in. Access restrictions apply. 287*0Sstevel@tonic-gate Net::FTP=GLOB(0x8152974)>>> QUIT 288*0Sstevel@tonic-gate Net::FTP=GLOB(0x8152974)<<< 221 Goodbye. 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gateThe first few lines tell you the modules that Net::FTP uses and their versions, 291*0Sstevel@tonic-gatethis is useful data to me when a user reports a bug. The last seven lines 292*0Sstevel@tonic-gateshow the communication with the server. Each line has three parts. The first 293*0Sstevel@tonic-gatepart is the object itself, this is useful for separating the output 294*0Sstevel@tonic-gateif you are using multiple objects. The second part is either C<<<<<> to 295*0Sstevel@tonic-gateshow data coming from the server or C<>>>>> to show data 296*0Sstevel@tonic-gategoing to the server. The remainder of the line is the command 297*0Sstevel@tonic-gatebeing sent or response being received. 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate=head1 AUTHOR AND COPYRIGHT 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gateCopyright (c) 1997 Graham Barr. 302*0Sstevel@tonic-gateAll rights reserved. 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate=for html <hr> 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gateI<$Id: //depot/libnet/Net/libnetFAQ.pod#6 $> 307*0Sstevel@tonic-gate 308