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