xref: /openbsd-src/gnu/usr.bin/perl/cpan/libnet/lib/Net/libnetFAQ.pod (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1b8851fccSafresh1=head1 NAME
2b8851fccSafresh1
3b8851fccSafresh1libnetFAQ - libnet Frequently Asked Questions
4b8851fccSafresh1
5b8851fccSafresh1=head1 DESCRIPTION
6b8851fccSafresh1
7b8851fccSafresh1=head2 Where to get this document
8b8851fccSafresh1
9b8851fccSafresh1This document is distributed with the libnet distribution, and is also
10b8851fccSafresh1available on the libnet web page at
11b8851fccSafresh1
12*eac174f2Safresh1L<https://metacpan.org/release/libnet>
13b8851fccSafresh1
14b8851fccSafresh1=head2 How to contribute to this document
15b8851fccSafresh1
16b8851fccSafresh1You may report corrections, additions, and suggestions on the
17b8851fccSafresh1CPAN Request Tracker at
18b8851fccSafresh1
19*eac174f2Safresh1L<https://rt.cpan.org/Public/Bug/Report.html?Queue=libnet>
20b8851fccSafresh1
21b8851fccSafresh1=head1 Author and Copyright Information
22b8851fccSafresh1
235759b3d2Safresh1Copyright (C) 1997-1998 Graham Barr.  All rights reserved.
24*eac174f2Safresh1This document is free; you can redistribute it and/or modify it under
25*eac174f2Safresh1the same terms as Perl itself, i.e. under the terms of either the GNU
26*eac174f2Safresh1General Public License or the Artistic License, as specified in the
27*eac174f2Safresh1F<LICENCE> file.
28b8851fccSafresh1
29*eac174f2Safresh1Steve Hay E<lt>L<shay@cpan.org|mailto:shay@cpan.org>E<gt> is now maintaining
30*eac174f2Safresh1libnet as of version 1.22_02.
31b8851fccSafresh1
32b8851fccSafresh1=head2 Disclaimer
33b8851fccSafresh1
34b8851fccSafresh1This information is offered in good faith and in the hope that it may
35b8851fccSafresh1be of use, but is not guaranteed to be correct, up to date, or suitable
36b8851fccSafresh1for any particular purpose whatsoever.  The authors accept no liability
37b8851fccSafresh1in respect of this information or its use.
38b8851fccSafresh1
39b8851fccSafresh1
40b8851fccSafresh1=head1 Obtaining and installing libnet
41b8851fccSafresh1
42b8851fccSafresh1=head2 What is libnet ?
43b8851fccSafresh1
44b8851fccSafresh1libnet is a collection of perl5 modules which all related to network
45b8851fccSafresh1programming. The majority of the modules available provided the
46b8851fccSafresh1client side of popular server-client protocols that are used in
47b8851fccSafresh1the internet community.
48b8851fccSafresh1
49b8851fccSafresh1=head2 Which version of perl do I need ?
50b8851fccSafresh1
51b8851fccSafresh1This version of libnet requires Perl 5.8.1 or higher.
52b8851fccSafresh1
53b8851fccSafresh1=head2 What other modules do I need ?
54b8851fccSafresh1
55b8851fccSafresh1No non-core modules are required for normal use, except on os390,
56b8851fccSafresh1which requires Convert::EBCDIC.
57b8851fccSafresh1
58b8851fccSafresh1Authen::SASL is required for AUTH support.
59b8851fccSafresh1
60b8851fccSafresh1IO::Socket::SSL version 2.007 or higher is required for SSL support.
61b8851fccSafresh1
625759b3d2Safresh1IO::Socket::IP version 0.25 or IO::Socket::INET6 version 2.62 is
63b8851fccSafresh1required for IPv6 support.
64b8851fccSafresh1
65b8851fccSafresh1=head2 What machines support libnet ?
66b8851fccSafresh1
67b8851fccSafresh1libnet itself is an entirely perl-code distribution so it should work
68b8851fccSafresh1on any machine that perl runs on.
69b8851fccSafresh1
70b8851fccSafresh1=head2 Where can I get the latest libnet release
71b8851fccSafresh1
72b8851fccSafresh1The latest libnet release is always on CPAN, you will find it
73b8851fccSafresh1in
74b8851fccSafresh1
75*eac174f2Safresh1L<https://metacpan.org/release/libnet>
76b8851fccSafresh1
77b8851fccSafresh1=head1 Using Net::FTP
78b8851fccSafresh1
79b8851fccSafresh1=head2 How do I download files from an FTP server ?
80b8851fccSafresh1
81b8851fccSafresh1An example taken from an article posted to comp.lang.perl.misc
82b8851fccSafresh1
83b8851fccSafresh1    #!/your/path/to/perl
84b8851fccSafresh1
85b8851fccSafresh1    # a module making life easier
86b8851fccSafresh1
87b8851fccSafresh1    use Net::FTP;
88b8851fccSafresh1
89b8851fccSafresh1    # for debugging: $ftp = Net::FTP->new('site','Debug',10);
90b8851fccSafresh1    # open a connection and log in!
91b8851fccSafresh1
92b8851fccSafresh1    $ftp = Net::FTP->new('target_site.somewhere.xxx');
93b8851fccSafresh1    $ftp->login('username','password');
94b8851fccSafresh1
95b8851fccSafresh1    # set transfer mode to binary
96b8851fccSafresh1
97b8851fccSafresh1    $ftp->binary();
98b8851fccSafresh1
99b8851fccSafresh1    # change the directory on the ftp site
100b8851fccSafresh1
101b8851fccSafresh1    $ftp->cwd('/some/path/to/somewhere/');
102b8851fccSafresh1
103b8851fccSafresh1    foreach $name ('file1', 'file2', 'file3') {
104b8851fccSafresh1
105b8851fccSafresh1    # get's arguments are in the following order:
106b8851fccSafresh1    # ftp server's filename
107b8851fccSafresh1    # filename to save the transfer to on the local machine
108b8851fccSafresh1    # can be simply used as get($name) if you want the same name
109b8851fccSafresh1
110b8851fccSafresh1      $ftp->get($name,$name);
111b8851fccSafresh1    }
112b8851fccSafresh1
113b8851fccSafresh1    # ftp done!
114b8851fccSafresh1
115b8851fccSafresh1    $ftp->quit;
116b8851fccSafresh1
117b8851fccSafresh1=head2 How do I transfer files in binary mode ?
118b8851fccSafresh1
119b8851fccSafresh1To transfer files without <LF><CR> translation Net::FTP provides
120b8851fccSafresh1the C<binary> method
121b8851fccSafresh1
122b8851fccSafresh1    $ftp->binary;
123b8851fccSafresh1
124b8851fccSafresh1=head2 How can I get the size of a file on a remote FTP server ?
125b8851fccSafresh1
126b8851fccSafresh1=head2 How can I get the modification time of a file on a remote FTP server ?
127b8851fccSafresh1
128b8851fccSafresh1=head2 How can I change the permissions of a file on a remote server ?
129b8851fccSafresh1
130b8851fccSafresh1The FTP protocol does not have a command for changing the permissions
131b8851fccSafresh1of a file on the remote server. But some ftp servers may allow a chmod
132b8851fccSafresh1command to be issued via a SITE command, eg
133b8851fccSafresh1
134b8851fccSafresh1    $ftp->quot('site chmod 0777',$filename);
135b8851fccSafresh1
136b8851fccSafresh1But this is not guaranteed to work.
137b8851fccSafresh1
138b8851fccSafresh1=head2 Can I do a reget operation like the ftp command ?
139b8851fccSafresh1
140b8851fccSafresh1=head2 How do I get a directory listing from an FTP server ?
141b8851fccSafresh1
142b8851fccSafresh1=head2 Changing directory to "" does not fail ?
143b8851fccSafresh1
144b8851fccSafresh1Passing an argument of "" to ->cwd() has the same affect of calling ->cwd()
145b8851fccSafresh1without any arguments. Turn on Debug (I<See below>) and you will see what is
146b8851fccSafresh1happening
147b8851fccSafresh1
148b8851fccSafresh1    $ftp = Net::FTP->new($host, Debug => 1);
149b8851fccSafresh1    $ftp->login;
150b8851fccSafresh1    $ftp->cwd("");
151b8851fccSafresh1
152b8851fccSafresh1gives
153b8851fccSafresh1
154b8851fccSafresh1    Net::FTP=GLOB(0x82196d8)>>> CWD /
155b8851fccSafresh1    Net::FTP=GLOB(0x82196d8)<<< 250 CWD command successful.
156b8851fccSafresh1
157b8851fccSafresh1=head2 I am behind a SOCKS firewall, but the Firewall option does not work ?
158b8851fccSafresh1
159b8851fccSafresh1The Firewall option is only for support of one type of firewall. The type
160b8851fccSafresh1supported is an ftp proxy.
161b8851fccSafresh1
162b8851fccSafresh1To use Net::FTP, or any other module in the libnet distribution,
163b8851fccSafresh1through a SOCKS firewall you must create a socks-ified perl executable
164b8851fccSafresh1by compiling perl with the socks library.
165b8851fccSafresh1
166b8851fccSafresh1=head2 I am behind an FTP proxy firewall, but cannot access machines outside ?
167b8851fccSafresh1
168b8851fccSafresh1Net::FTP implements the most popular ftp proxy firewall approach. The scheme
169b8851fccSafresh1implemented is that where you log in to the firewall with C<user@hostname>
170b8851fccSafresh1
171b8851fccSafresh1I have heard of one other type of firewall which requires a login to the
172b8851fccSafresh1firewall with an account, then a second login with C<user@hostname>. You can
173b8851fccSafresh1still use Net::FTP to traverse these firewalls, but a more manual approach
174b8851fccSafresh1must be taken, eg
175b8851fccSafresh1
176b8851fccSafresh1    $ftp = Net::FTP->new($firewall) or die $@;
177b8851fccSafresh1    $ftp->login($firewall_user, $firewall_passwd) or die $ftp->message;
178b8851fccSafresh1    $ftp->login($ext_user . '@' . $ext_host, $ext_passwd) or die $ftp->message.
179b8851fccSafresh1
180b8851fccSafresh1=head2 My ftp proxy firewall does not listen on port 21
181b8851fccSafresh1
182b8851fccSafresh1FTP servers usually listen on the same port number, port 21, as any other
183b8851fccSafresh1FTP server. But there is no reason why this has to be the case.
184b8851fccSafresh1
185b8851fccSafresh1If you pass a port number to Net::FTP then it assumes this is the port
186b8851fccSafresh1number of the final destination. By default Net::FTP will always try
187b8851fccSafresh1to connect to the firewall on port 21.
188b8851fccSafresh1
189b8851fccSafresh1Net::FTP uses IO::Socket to open the connection and IO::Socket allows
190b8851fccSafresh1the port number to be specified as part of the hostname. So this problem
191b8851fccSafresh1can be resolved by either passing a Firewall option like C<"hostname:1234">
192b8851fccSafresh1or by setting the C<ftp_firewall> option in Net::Config to be a string
193b8851fccSafresh1in the same form.
194b8851fccSafresh1
195b8851fccSafresh1=head2 Is it possible to change the file permissions of a file on an FTP server ?
196b8851fccSafresh1
197b8851fccSafresh1The answer to this is "maybe". The FTP protocol does not specify a command to change
198b8851fccSafresh1file permissions on a remote host. However many servers do allow you to run the
199b8851fccSafresh1chmod command via the C<SITE> command. This can be done with
200b8851fccSafresh1
201b8851fccSafresh1  $ftp->site('chmod','0775',$file);
202b8851fccSafresh1
203b8851fccSafresh1=head2 I have seen scripts call a method message, but cannot find it documented ?
204b8851fccSafresh1
205b8851fccSafresh1Net::FTP, like several other packages in libnet, inherits from Net::Cmd, so
206b8851fccSafresh1all the methods described in Net::Cmd are also available on Net::FTP
207b8851fccSafresh1objects.
208b8851fccSafresh1
209b8851fccSafresh1=head2 Why does Net::FTP not implement mput and mget methods
210b8851fccSafresh1
211b8851fccSafresh1The quick answer is because they are easy to implement yourself. The long
212b8851fccSafresh1answer is that to write these in such a way that multiple platforms are
213b8851fccSafresh1supported correctly would just require too much code. Below are
214b8851fccSafresh1some examples how you can implement these yourself.
215b8851fccSafresh1
216b8851fccSafresh1sub mput {
217b8851fccSafresh1  my($ftp,$pattern) = @_;
218b8851fccSafresh1  foreach my $file (glob($pattern)) {
219b8851fccSafresh1    $ftp->put($file) or warn $ftp->message;
220b8851fccSafresh1  }
221b8851fccSafresh1}
222b8851fccSafresh1
223b8851fccSafresh1sub mget {
224b8851fccSafresh1  my($ftp,$pattern) = @_;
225b8851fccSafresh1  foreach my $file ($ftp->ls($pattern)) {
226b8851fccSafresh1    $ftp->get($file) or warn $ftp->message;
227b8851fccSafresh1  }
228b8851fccSafresh1}
229b8851fccSafresh1
230b8851fccSafresh1
231b8851fccSafresh1=head1 Using Net::SMTP
232b8851fccSafresh1
233b8851fccSafresh1=head2 Why can't the part of an Email address after the @ be used as the hostname ?
234b8851fccSafresh1
235b8851fccSafresh1The part of an Email address which follows the @ is not necessarily a hostname,
236b8851fccSafresh1it is a mail domain. To find the name of a host to connect for a mail domain
237b8851fccSafresh1you need to do a DNS MX lookup
238b8851fccSafresh1
239b8851fccSafresh1=head2 Why does Net::SMTP not do DNS MX lookups ?
240b8851fccSafresh1
241b8851fccSafresh1Net::SMTP implements the SMTP protocol. The DNS MX lookup is not part
242b8851fccSafresh1of this protocol.
243b8851fccSafresh1
244b8851fccSafresh1=head2 The verify method always returns true ?
245b8851fccSafresh1
246b8851fccSafresh1Well it may seem that way, but it does not. The verify method returns true
247b8851fccSafresh1if the command succeeded. If you pass verify an address which the
248b8851fccSafresh1server would normally have to forward to another machine, the command
249b8851fccSafresh1will succeed with something like
250b8851fccSafresh1
251b8851fccSafresh1    252 Couldn't verify <someone@there> but will attempt delivery anyway
252b8851fccSafresh1
253b8851fccSafresh1This command will fail only if you pass it an address in a domain
254b8851fccSafresh1the server directly delivers for, and that address does not exist.
255b8851fccSafresh1
256b8851fccSafresh1=head1 Debugging scripts
257b8851fccSafresh1
258b8851fccSafresh1=head2 How can I debug my scripts that use Net::* modules ?
259b8851fccSafresh1
260b8851fccSafresh1Most of the libnet client classes allow options to be passed to the
261b8851fccSafresh1constructor, in most cases one option is called C<Debug>. Passing
262b8851fccSafresh1this option with a non-zero value will turn on a protocol trace, which
263b8851fccSafresh1will be sent to STDERR. This trace can be useful to see what commands
264b8851fccSafresh1are being sent to the remote server and what responses are being
265b8851fccSafresh1received back.
266b8851fccSafresh1
267b8851fccSafresh1    #!/your/path/to/perl
268b8851fccSafresh1
269b8851fccSafresh1    use Net::FTP;
270b8851fccSafresh1
271b8851fccSafresh1    my $ftp = new Net::FTP($host, Debug => 1);
272b8851fccSafresh1    $ftp->login('gbarr','password');
273b8851fccSafresh1    $ftp->quit;
274b8851fccSafresh1
275b8851fccSafresh1this script would output something like
276b8851fccSafresh1
277b8851fccSafresh1 Net::FTP: Net::FTP(2.22)
278b8851fccSafresh1 Net::FTP:   Exporter
279b8851fccSafresh1 Net::FTP:   Net::Cmd(2.0801)
280b8851fccSafresh1 Net::FTP:   IO::Socket::INET
281b8851fccSafresh1 Net::FTP:     IO::Socket(1.1603)
282b8851fccSafresh1 Net::FTP:       IO::Handle(1.1504)
283b8851fccSafresh1
284b8851fccSafresh1 Net::FTP=GLOB(0x8152974)<<< 220 imagine FTP server (Version wu-2.4(5) Tue Jul 29 11:17:18 CDT 1997) ready.
285b8851fccSafresh1 Net::FTP=GLOB(0x8152974)>>> user gbarr
286b8851fccSafresh1 Net::FTP=GLOB(0x8152974)<<< 331 Password required for gbarr.
287b8851fccSafresh1 Net::FTP=GLOB(0x8152974)>>> PASS ....
288b8851fccSafresh1 Net::FTP=GLOB(0x8152974)<<< 230 User gbarr logged in.  Access restrictions apply.
289b8851fccSafresh1 Net::FTP=GLOB(0x8152974)>>> QUIT
290b8851fccSafresh1 Net::FTP=GLOB(0x8152974)<<< 221 Goodbye.
291b8851fccSafresh1
292b8851fccSafresh1The first few lines tell you the modules that Net::FTP uses and their versions,
293b8851fccSafresh1this is useful data to me when a user reports a bug. The last seven lines
294b8851fccSafresh1show the communication with the server. Each line has three parts. The first
295b8851fccSafresh1part is the object itself, this is useful for separating the output
296b8851fccSafresh1if you are using multiple objects. The second part is either C<<<<<> to
297b8851fccSafresh1show data coming from the server or C<&gt&gt&gt&gt> to show data
298b8851fccSafresh1going to the server. The remainder of the line is the command
299b8851fccSafresh1being sent or response being received.
300b8851fccSafresh1
301b8851fccSafresh1=head1 AUTHOR AND COPYRIGHT
302b8851fccSafresh1
3035759b3d2Safresh1Copyright (C) 1997-1998 Graham Barr.  All rights reserved.
304