source: for-distributions/trunk/bin/windows/perl/lib/Net/libnetFAQ.pod@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

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