1Net::libnetFAQ(3pm)    Perl Programmers Reference Guide    Net::libnetFAQ(3pm)
2
3
4

NAME

6       libnetFAQ - libnet Frequently Asked Questions
7

DESCRIPTION

9       Where to get this document
10
11       This document is distributed with the libnet distribution, and is also
12       available on the libnet web page at
13
14           http://search.cpan.org/~gbarr/libnet/
15
16       How to contribute to this document
17
18       You may mail corrections, additions, and suggestions to me
19       gbarr@pobox.com.
20
22       Copyright (c) 1997-1998 Graham Barr. All rights reserved.  This docu‐
23       ment is free; you can redistribute it and/or modify it under the terms
24       of the Artistic License.
25
26       Disclaimer
27
28       This information is offered in good faith and in the hope that it may
29       be of use, but is not guaranteed to be correct, up to date, or suitable
30       for any particular purpose whatsoever.  The authors accept no liability
31       in respect of this information or its use.
32

Obtaining and installing libnet

34       What is libnet ?
35
36       libnet is a collection of perl5 modules which all related to network
37       programming. The majority of the modules available provided the client
38       side of popular server-client protocols that are used in the internet
39       community.
40
41       Which version of perl do I need ?
42
43       libnet has been know to work with versions of perl from 5.002 onwards.
44       However if your release of perl is prior to perl5.004 then you will
45       need to obtain and install the IO distribution from CPAN. If you have
46       perl5.004 or later then you will have the IO modules in your installa‐
47       tion already, but CPAN may contain updates.
48
49       What other modules do I need ?
50
51       The only modules you will need installed are the modules from the IO
52       distribution. If you have perl5.004 or later you will already have
53       these modules.
54
55       What machines support libnet ?
56
57       libnet itself is an entirely perl-code distribution so it should work
58       on any machine that perl runs on. However IO may not work with some
59       machines and earlier releases of perl. But this should not be the case
60       with perl version 5.004 or later.
61
62       Where can I get the latest libnet release
63
64       The latest libnet release is always on CPAN, you will find it in
65
66        http://www.cpan.org/modules/by-module/Net/
67
68       The latest release and information is also available on the libnet web
69       page at
70
71        http://search.cpan.org/~gbarr/libnet/
72

Using Net::FTP

74       How do I download files from an FTP server ?
75
76       An example taken from an article posted to comp.lang.perl.misc
77
78           #!/your/path/to/perl
79
80           # a module making life easier
81
82           use Net::FTP;
83
84           # for debuging: $ftp = Net::FTP->new('site','Debug',10);
85           # open a connection and log in!
86
87           $ftp = Net::FTP->new('target_site.somewhere.xxx');
88           $ftp->login('username','password');
89
90           # set transfer mode to binary
91
92           $ftp->binary();
93
94           # change the directory on the ftp site
95
96           $ftp->cwd('/some/path/to/somewhere/');
97
98           foreach $name ('file1', 'file2', 'file3') {
99
100           # get's arguments are in the following order:
101           # ftp server's filename
102           # filename to save the transfer to on the local machine
103           # can be simply used as get($name) if you want the same name
104
105             $ftp->get($name,$name);
106           }
107
108           # ftp done!
109
110           $ftp->quit;
111
112       How do I transfer files in binary mode ?
113
114       To transfer files without <LF><CR> translation Net::FTP provides the
115       "binary" method
116
117           $ftp->binary;
118
119       How can I get the size of a file on a remote FTP server ?
120
121       How can I get the modification time of a file on a remote FTP server ?
122
123       How can I change the permissions of a file on a remote server ?
124
125       The FTP protocol does not have a command for changing the permissions
126       of a file on the remote server. But some ftp servers may allow a chmod
127       command to be issued via a SITE command, eg
128
129           $ftp->quot('site chmod 0777',$filename);
130
131       But this is not guaranteed to work.
132
133       Can I do a reget operation like the ftp command ?
134
135       How do I get a directory listing from an FTP server ?
136
137       Changing directory to "" does not fail ?
138
139       Passing an argument of "" to ->cwd() has the same affect of calling
140       ->cwd() without any arguments. Turn on Debug (See below) and you will
141       see what is happening
142
143           $ftp = Net::FTP->new($host, Debug => 1);
144           $ftp->login;
145           $ftp->cwd("");
146
147       gives
148
149           Net::FTP=GLOB(0x82196d8)>>> CWD /
150           Net::FTP=GLOB(0x82196d8)<<< 250 CWD command successful.
151
152       I am behind a SOCKS firewall, but the Firewall option does not work ?
153
154       The Firewall option is only for support of one type of firewall. The
155       type supported is an ftp proxy.
156
157       To use Net::FTP, or any other module in the libnet distribution,
158       through a SOCKS firewall you must create a socks-ified perl executable
159       by compiling perl with the socks library.
160
161       I am behind an FTP proxy firewall, but cannot access machines outside ?
162
163       Net::FTP implements the most popular ftp proxy firewall approach. The
164       scheme implemented is that where you log in to the firewall with
165       "user@hostname"
166
167       I have heard of one other type of firewall which requires a login to
168       the firewall with an account, then a second login with "user@hostname".
169       You can still use Net::FTP to traverse these firewalls, but a more man‐
170       ual approach must be taken, eg
171
172           $ftp = Net::FTP->new($firewall) or die $@;
173           $ftp->login($firewall_user, $firewall_passwd) or die $ftp->message;
174           $ftp->login($ext_user . '@' . $ext_host, $ext_passwd) or die $ftp->message.
175
176       My ftp proxy firewall does not listen on port 21
177
178       FTP servers usually listen on the same port number, port 21, as any
179       other FTP server. But there is no reason why this has to be the case.
180
181       If you pass a port number to Net::FTP then it assumes this is the port
182       number of the final destination. By default Net::FTP will always try to
183       connect to the firewall on port 21.
184
185       Net::FTP uses IO::Socket to open the connection and IO::Socket allows
186       the port number to be specified as part of the hostname. So this prob‐
187       lem can be resolved by either passing a Firewall option like "host‐
188       name:1234" or by setting the "ftp_firewall" option in Net::Config to be
189       a string in in the same form.
190
191       Is it possible to change the file permissions of a file on an FTP
192       server ?
193
194       The answer to this is "maybe". The FTP protocol does not specify a com‐
195       mand to change file permissions on a remote host. However many servers
196       do allow you to run the chmod command via the "SITE" command. This can
197       be done with
198
199         $ftp->site('chmod','0775',$file);
200
201       I have seen scripts call a method message, but cannot find it docu‐
202       mented ?
203
204       Net::FTP, like several other packages in libnet, inherits from
205       Net::Cmd, so all the methods described in Net::Cmd are also available
206       on Net::FTP objects.
207
208       Why does Net::FTP not implement mput and mget methods
209
210       The quick answer is because they are easy to implement yourself. The
211       long answer is that to write these in such a way that multiple plat‐
212       forms are supported correctly would just require too much code. Below
213       are some examples how you can implement these yourself.
214
215       sub mput {
216         my($ftp,$pattern) = @_;
217         foreach my $file (glob($pattern)) {
218           $ftp->put($file) or warn $ftp->message;
219         } }
220
221       sub mget {
222         my($ftp,$pattern) = @_;
223         foreach my $file ($ftp->ls($pattern)) {
224           $ftp->get($file) or warn $ftp->message;
225         } }
226

Using Net::SMTP

228       Why can't the part of an Email address after the @ be used as the host‐
229       name ?
230
231       The part of an Email address which follows the @ is not necessarily a
232       hostname, it is a mail domain. To find the name of a host to connect
233       for a mail domain you need to do a DNS MX lookup
234
235       Why does Net::SMTP not do DNS MX lookups ?
236
237       Net::SMTP implements the SMTP protocol. The DNS MX lookup is not part
238       of this protocol.
239
240       The verify method always returns true ?
241
242       Well it may seem that way, but it does not. The verify method returns
243       true if the command succeeded. If you pass verify an address which the
244       server would normally have to forward to another machine, the command
245       will succeed with something like
246
247           252 Couldn't verify <someone@there> but will attempt delivery anyway
248
249       This command will fail only if you pass it an address in a domain the
250       server directly delivers for, and that address does not exist.
251

Debugging scripts

253       How can I debug my scripts that use Net::* modules ?
254
255       Most of the libnet client classes allow options to be passed to the
256       constructor, in most cases one option is called "Debug". Passing this
257       option with a non-zero value will turn on a protocol trace, which will
258       be sent to STDERR. This trace can be useful to see what commands are
259       being sent to the remote server and what responses are being received
260       back.
261
262           #!/your/path/to/perl
263
264           use Net::FTP;
265
266           my $ftp = new Net::FTP($host, Debug => 1);
267           $ftp->login('gbarr','password');
268           $ftp->quit;
269
270       this script would output something like
271
272        Net::FTP: Net::FTP(2.22)
273        Net::FTP:   Exporter
274        Net::FTP:   Net::Cmd(2.0801)
275        Net::FTP:   IO::Socket::INET
276        Net::FTP:     IO::Socket(1.1603)
277        Net::FTP:       IO::Handle(1.1504)
278
279        Net::FTP=GLOB(0x8152974)<<< 220 imagine FTP server (Version wu-2.4(5) Tue Jul 29 11:17:18 CDT 1997) ready.
280        Net::FTP=GLOB(0x8152974)>>> user gbarr
281        Net::FTP=GLOB(0x8152974)<<< 331 Password required for gbarr.
282        Net::FTP=GLOB(0x8152974)>>> PASS ....
283        Net::FTP=GLOB(0x8152974)<<< 230 User gbarr logged in.  Access restrictions apply.
284        Net::FTP=GLOB(0x8152974)>>> QUIT
285        Net::FTP=GLOB(0x8152974)<<< 221 Goodbye.
286
287       The first few lines tell you the modules that Net::FTP uses and their
288       versions, this is useful data to me when a user reports a bug. The last
289       seven lines show the communication with the server. Each line has three
290       parts. The first part is the object itself, this is useful for separat‐
291       ing the output if you are using multiple objects. The second part is
292       either "<<<<" to show data coming from the server or "&gt&gt&gt&gt" to
293       show data going to the server. The remainder of the line is the command
294       being sent or response being received.
295
297       Copyright (c) 1997 Graham Barr.  All rights reserved.
298
299       $Id: //depot/libnet/Net/libnetFAQ.pod#6 $
300
301
302
303perl v5.8.8                       2001-09-21               Net::libnetFAQ(3pm)
Impressum