1N/A=head1 NAME
1N/A
1N/AlibnetFAQ - libnet Frequently Asked Questions
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/A=head2 Where to get this document
1N/A
1N/AThis document is distributed with the libnet distribution, and is also
1N/Aavailable on the libnet web page at
1N/A
1N/A http://search.cpan.org/~gbarr/libnet/
1N/A
1N/A=head2 How to contribute to this document
1N/A
1N/AYou may mail corrections, additions, and suggestions to me
1N/Agbarr@pobox.com.
1N/A
1N/A=head1 Author and Copyright Information
1N/A
1N/ACopyright (c) 1997-1998 Graham Barr. All rights reserved.
1N/AThis document is free; you can redistribute it and/or modify it
1N/Aunder the terms of the Artistic License.
1N/A
1N/A=head2 Disclaimer
1N/A
1N/AThis information is offered in good faith and in the hope that it may
1N/Abe of use, but is not guaranteed to be correct, up to date, or suitable
1N/Afor any particular purpose whatsoever. The authors accept no liability
1N/Ain respect of this information or its use.
1N/A
1N/A
1N/A=head1 Obtaining and installing libnet
1N/A
1N/A=head2 What is libnet ?
1N/A
1N/Alibnet is a collection of perl5 modules which all related to network
1N/Aprogramming. The majority of the modules available provided the
1N/Aclient side of popular server-client protocols that are used in
1N/Athe internet community.
1N/A
1N/A=head2 Which version of perl do I need ?
1N/A
1N/Alibnet has been know to work with versions of perl from 5.002 onwards. However
1N/Aif your release of perl is prior to perl5.004 then you will need to
1N/Aobtain and install the IO distribution from CPAN. If you have perl5.004
1N/Aor later then you will have the IO modules in your installation already,
1N/Abut CPAN may contain updates.
1N/A
1N/A=head2 What other modules do I need ?
1N/A
1N/AThe only modules you will need installed are the modules from the IO
1N/Adistribution. If you have perl5.004 or later you will already have
1N/Athese modules.
1N/A
1N/A=head2 What machines support libnet ?
1N/A
1N/Alibnet itself is an entirely perl-code distribution so it should work
1N/Aon any machine that perl runs on. However IO may not work
1N/Awith some machines and earlier releases of perl. But this
1N/Ashould not be the case with perl version 5.004 or later.
1N/A
1N/A=head2 Where can I get the latest libnet release
1N/A
1N/AThe latest libnet release is always on CPAN, you will find it
1N/Ain
1N/A
1N/A http://www.cpan.org/modules/by-module/Net/
1N/A
1N/AThe latest release and information is also available on the libnet web page
1N/Aat
1N/A
1N/A http://search.cpan.org/~gbarr/libnet/
1N/A
1N/A=head1 Using Net::FTP
1N/A
1N/A=head2 How do I download files from an FTP server ?
1N/A
1N/AAn example taken from an article posted to comp.lang.perl.misc
1N/A
1N/A #!/your/path/to/perl
1N/A
1N/A # a module making life easier
1N/A
1N/A use Net::FTP;
1N/A
1N/A # for debuging: $ftp = Net::FTP->new('site','Debug',10);
1N/A # open a connection and log in!
1N/A
1N/A $ftp = Net::FTP->new('target_site.somewhere.xxx');
1N/A $ftp->login('username','password');
1N/A
1N/A # set transfer mode to binary
1N/A
1N/A $ftp->binary();
1N/A
1N/A # change the directory on the ftp site
1N/A
1N/A $ftp->cwd('/some/path/to/somewhere/');
1N/A
1N/A foreach $name ('file1', 'file2', 'file3') {
1N/A
1N/A # get's arguments are in the following order:
1N/A # ftp server's filename
1N/A # filename to save the transfer to on the local machine
1N/A # can be simply used as get($name) if you want the same name
1N/A
1N/A $ftp->get($name,$name);
1N/A }
1N/A
1N/A # ftp done!
1N/A
1N/A $ftp->quit;
1N/A
1N/A=head2 How do I transfer files in binary mode ?
1N/A
1N/ATo transfer files without <LF><CR> translation Net::FTP provides
1N/Athe C<binary> method
1N/A
1N/A $ftp->binary;
1N/A
1N/A=head2 How can I get the size of a file on a remote FTP server ?
1N/A
1N/A=head2 How can I get the modification time of a file on a remote FTP server ?
1N/A
1N/A=head2 How can I change the permissions of a file on a remote server ?
1N/A
1N/AThe FTP protocol does not have a command for changing the permissions
1N/Aof a file on the remote server. But some ftp servers may allow a chmod
1N/Acommand to be issued via a SITE command, eg
1N/A
1N/A $ftp->quot('site chmod 0777',$filename);
1N/A
1N/ABut this is not guaranteed to work.
1N/A
1N/A=head2 Can I do a reget operation like the ftp command ?
1N/A
1N/A=head2 How do I get a directory listing from an FTP server ?
1N/A
1N/A=head2 Changing directory to "" does not fail ?
1N/A
1N/APassing an argument of "" to ->cwd() has the same affect of calling ->cwd()
1N/Awithout any arguments. Turn on Debug (I<See below>) and you will see what is
1N/Ahappening
1N/A
1N/A $ftp = Net::FTP->new($host, Debug => 1);
1N/A $ftp->login;
1N/A $ftp->cwd("");
1N/A
1N/Agives
1N/A
1N/A Net::FTP=GLOB(0x82196d8)>>> CWD /
1N/A Net::FTP=GLOB(0x82196d8)<<< 250 CWD command successful.
1N/A
1N/A=head2 I am behind a SOCKS firewall, but the Firewall option does not work ?
1N/A
1N/AThe Firewall option is only for support of one type of firewall. The type
1N/Asupported is an ftp proxy.
1N/A
1N/ATo use Net::FTP, or any other module in the libnet distribution,
1N/Athrough a SOCKS firewall you must create a socks-ified perl executable
1N/Aby compiling perl with the socks library.
1N/A
1N/A=head2 I am behind an FTP proxy firewall, but cannot access machines outside ?
1N/A
1N/ANet::FTP implements the most popular ftp proxy firewall approach. The scheme
1N/Aimplemented is that where you log in to the firewall with C<user@hostname>
1N/A
1N/AI have heard of one other type of firewall which requires a login to the
1N/Afirewall with an account, then a second login with C<user@hostname>. You can
1N/Astill use Net::FTP to traverse these firewalls, but a more manual approach
1N/Amust be taken, eg
1N/A
1N/A $ftp = Net::FTP->new($firewall) or die $@;
1N/A $ftp->login($firewall_user, $firewall_passwd) or die $ftp->message;
1N/A $ftp->login($ext_user . '@' . $ext_host, $ext_passwd) or die $ftp->message.
1N/A
1N/A=head2 My ftp proxy firewall does not listen on port 21
1N/A
1N/AFTP servers usually listen on the same port number, port 21, as any other
1N/AFTP server. But there is no reason why this has to be the case.
1N/A
1N/AIf you pass a port number to Net::FTP then it assumes this is the port
1N/Anumber of the final destination. By default Net::FTP will always try
1N/Ato connect to the firewall on port 21.
1N/A
1N/ANet::FTP uses IO::Socket to open the connection and IO::Socket allows
1N/Athe port number to be specified as part of the hostname. So this problem
1N/Acan be resolved by either passing a Firewall option like C<"hostname:1234">
1N/Aor by setting the C<ftp_firewall> option in Net::Config to be a string
1N/Ain in the same form.
1N/A
1N/A=head2 Is it possible to change the file permissions of a file on an FTP server ?
1N/A
1N/AThe answer to this is "maybe". The FTP protocol does not specify a command to change
1N/Afile permissions on a remote host. However many servers do allow you to run the
1N/Achmod command via the C<SITE> command. This can be done with
1N/A
1N/A $ftp->site('chmod','0775',$file);
1N/A
1N/A=head2 I have seen scripts call a method message, but cannot find it documented ?
1N/A
1N/ANet::FTP, like several other packages in libnet, inherits from Net::Cmd, so
1N/Aall the methods described in Net::Cmd are also available on Net::FTP
1N/Aobjects.
1N/A
1N/A=head2 Why does Net::FTP not implement mput and mget methods
1N/A
1N/AThe quick answer is because they are easy to implement yourself. The long
1N/Aanswer is that to write these in such a way that multiple platforms are
1N/Asupported correctly would just require too much code. Below are
1N/Asome examples how you can implement these yourself.
1N/A
1N/Asub mput {
1N/A my($ftp,$pattern) = @_;
1N/A foreach my $file (glob($pattern)) {
1N/A $ftp->put($file) or warn $ftp->message;
1N/A }
1N/A}
1N/A
1N/Asub mget {
1N/A my($ftp,$pattern) = @_;
1N/A foreach my $file ($ftp->ls($pattern)) {
1N/A $ftp->get($file) or warn $ftp->message;
1N/A }
1N/A}
1N/A
1N/A
1N/A=head1 Using Net::SMTP
1N/A
1N/A=head2 Why can't the part of an Email address after the @ be used as the hostname ?
1N/A
1N/AThe part of an Email address which follows the @ is not necessarily a hostname,
1N/Ait is a mail domain. To find the name of a host to connect for a mail domain
1N/Ayou need to do a DNS MX lookup
1N/A
1N/A=head2 Why does Net::SMTP not do DNS MX lookups ?
1N/A
1N/ANet::SMTP implements the SMTP protocol. The DNS MX lookup is not part
1N/Aof this protocol.
1N/A
1N/A=head2 The verify method always returns true ?
1N/A
1N/AWell it may seem that way, but it does not. The verify method returns true
1N/Aif the command succeeded. If you pass verify an address which the
1N/Aserver would normally have to forward to another machine, the command
1N/Awill succeed with something like
1N/A
1N/A 252 Couldn't verify <someone@there> but will attempt delivery anyway
1N/A
1N/AThis command will fail only if you pass it an address in a domain
1N/Athe server directly delivers for, and that address does not exist.
1N/A
1N/A=head1 Debugging scripts
1N/A
1N/A=head2 How can I debug my scripts that use Net::* modules ?
1N/A
1N/AMost of the libnet client classes allow options to be passed to the
1N/Aconstructor, in most cases one option is called C<Debug>. Passing
1N/Athis option with a non-zero value will turn on a protocol trace, which
1N/Awill be sent to STDERR. This trace can be useful to see what commands
1N/Aare being sent to the remote server and what responses are being
1N/Areceived back.
1N/A
1N/A #!/your/path/to/perl
1N/A
1N/A use Net::FTP;
1N/A
1N/A my $ftp = new Net::FTP($host, Debug => 1);
1N/A $ftp->login('gbarr','password');
1N/A $ftp->quit;
1N/A
1N/Athis script would output something like
1N/A
1N/A Net::FTP: Net::FTP(2.22)
1N/A Net::FTP: Exporter
1N/A Net::FTP: Net::Cmd(2.0801)
1N/A Net::FTP: IO::Socket::INET
1N/A Net::FTP: IO::Socket(1.1603)
1N/A Net::FTP: IO::Handle(1.1504)
1N/A
1N/A Net::FTP=GLOB(0x8152974)<<< 220 imagine FTP server (Version wu-2.4(5) Tue Jul 29 11:17:18 CDT 1997) ready.
1N/A Net::FTP=GLOB(0x8152974)>>> user gbarr
1N/A Net::FTP=GLOB(0x8152974)<<< 331 Password required for gbarr.
1N/A Net::FTP=GLOB(0x8152974)>>> PASS ....
1N/A Net::FTP=GLOB(0x8152974)<<< 230 User gbarr logged in. Access restrictions apply.
1N/A Net::FTP=GLOB(0x8152974)>>> QUIT
1N/A Net::FTP=GLOB(0x8152974)<<< 221 Goodbye.
1N/A
1N/AThe first few lines tell you the modules that Net::FTP uses and their versions,
1N/Athis is useful data to me when a user reports a bug. The last seven lines
1N/Ashow the communication with the server. Each line has three parts. The first
1N/Apart is the object itself, this is useful for separating the output
1N/Aif you are using multiple objects. The second part is either C<<<<<> to
1N/Ashow data coming from the server or C<&gt&gt&gt&gt> to show data
1N/Agoing to the server. The remainder of the line is the command
1N/Abeing sent or response being received.
1N/A
1N/A=head1 AUTHOR AND COPYRIGHT
1N/A
1N/ACopyright (c) 1997 Graham Barr.
1N/AAll rights reserved.
1N/A
1N/A=for html <hr>
1N/A
1N/AI<$Id: //depot/libnet/Net/libnetFAQ.pod#6 $>
1N/A