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