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