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