| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Net::libnetFAQ 3perl" |
| 58 |
.TH Net::libnetFAQ 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
libnetFAQ \- libnet Frequently Asked Questions |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
.SS "Where to get this document" |
| 68 |
.IX Subsection "Where to get this document" |
| 69 |
This document is distributed with the libnet distribution, and is also |
| 70 |
available on the libnet web page at |
| 71 |
.PP |
| 72 |
<https://metacpan.org/release/libnet> |
| 73 |
.SS "How to contribute to this document" |
| 74 |
.IX Subsection "How to contribute to this document" |
| 75 |
You may report corrections, additions, and suggestions on the |
| 76 |
CPAN Request Tracker at |
| 77 |
.PP |
| 78 |
<https://rt.cpan.org/Public/Bug/Report.html?Queue=libnet> |
| 79 |
.SH "Author and Copyright Information" |
| 80 |
.IX Header "Author and Copyright Information" |
| 81 |
Copyright (C) 1997\-1998 Graham Barr. All rights reserved. |
| 82 |
This document is free; you can redistribute it and/or modify it under |
| 83 |
the same terms as Perl itself, i.e. under the terms of either the GNU |
| 84 |
General Public License or the Artistic License, as specified in the |
| 85 |
\&\fILICENCE\fR file. |
| 86 |
.PP |
| 87 |
Steve Hay <[email protected] <mailto:[email protected]>> is now maintaining |
| 88 |
libnet as of version 1.22_02. |
| 89 |
.SS Disclaimer |
| 90 |
.IX Subsection "Disclaimer" |
| 91 |
This information is offered in good faith and in the hope that it may |
| 92 |
be of use, but is not guaranteed to be correct, up to date, or suitable |
| 93 |
for any particular purpose whatsoever. The authors accept no liability |
| 94 |
in respect of this information or its use. |
| 95 |
.SH "Obtaining and installing libnet" |
| 96 |
.IX Header "Obtaining and installing libnet" |
| 97 |
.SS "What is libnet ?" |
| 98 |
.IX Subsection "What is libnet ?" |
| 99 |
libnet is a collection of perl5 modules which all related to network |
| 100 |
programming. The majority of the modules available provided the |
| 101 |
client side of popular server-client protocols that are used in |
| 102 |
the internet community. |
| 103 |
.SS "Which version of perl do I need ?" |
| 104 |
.IX Subsection "Which version of perl do I need ?" |
| 105 |
This version of libnet requires Perl 5.8.1 or higher. |
| 106 |
.SS "What other modules do I need ?" |
| 107 |
.IX Subsection "What other modules do I need ?" |
| 108 |
No non-core modules are required for normal use, except on os390, |
| 109 |
which requires Convert::EBCDIC. |
| 110 |
.PP |
| 111 |
Authen::SASL is required for AUTH support. |
| 112 |
.PP |
| 113 |
IO::Socket::SSL version 2.007 or higher is required for SSL support. |
| 114 |
.PP |
| 115 |
IO::Socket::IP version 0.25 or IO::Socket::INET6 version 2.62 is |
| 116 |
required for IPv6 support. |
| 117 |
.SS "What machines support libnet ?" |
| 118 |
.IX Subsection "What machines support libnet ?" |
| 119 |
libnet itself is an entirely perl-code distribution so it should work |
| 120 |
on any machine that perl runs on. |
| 121 |
.SS "Where can I get the latest libnet release" |
| 122 |
.IX Subsection "Where can I get the latest libnet release" |
| 123 |
The latest libnet release is always on CPAN, you will find it |
| 124 |
in |
| 125 |
.PP |
| 126 |
<https://metacpan.org/release/libnet> |
| 127 |
.SH "Using Net::FTP" |
| 128 |
.IX Header "Using Net::FTP" |
| 129 |
.SS "How do I download files from an FTP server ?" |
| 130 |
.IX Subsection "How do I download files from an FTP server ?" |
| 131 |
An example taken from an article posted to comp.lang.perl.misc |
| 132 |
.PP |
| 133 |
.Vb 1 |
| 134 |
\& #!/your/path/to/perl |
| 135 |
\& |
| 136 |
\& # a module making life easier |
| 137 |
\& |
| 138 |
\& use Net::FTP; |
| 139 |
\& |
| 140 |
\& # for debugging: $ftp = Net::FTP\->new(\*(Aqsite\*(Aq,\*(AqDebug\*(Aq,10); |
| 141 |
\& # open a connection and log in! |
| 142 |
\& |
| 143 |
\& $ftp = Net::FTP\->new(\*(Aqtarget_site.somewhere.xxx\*(Aq); |
| 144 |
\& $ftp\->login(\*(Aqusername\*(Aq,\*(Aqpassword\*(Aq); |
| 145 |
\& |
| 146 |
\& # set transfer mode to binary |
| 147 |
\& |
| 148 |
\& $ftp\->binary(); |
| 149 |
\& |
| 150 |
\& # change the directory on the ftp site |
| 151 |
\& |
| 152 |
\& $ftp\->cwd(\*(Aq/some/path/to/somewhere/\*(Aq); |
| 153 |
\& |
| 154 |
\& foreach $name (\*(Aqfile1\*(Aq, \*(Aqfile2\*(Aq, \*(Aqfile3\*(Aq) { |
| 155 |
\& |
| 156 |
\& # get\*(Aqs arguments are in the following order: |
| 157 |
\& # ftp server\*(Aqs filename |
| 158 |
\& # filename to save the transfer to on the local machine |
| 159 |
\& # can be simply used as get($name) if you want the same name |
| 160 |
\& |
| 161 |
\& $ftp\->get($name,$name); |
| 162 |
\& } |
| 163 |
\& |
| 164 |
\& # ftp done! |
| 165 |
\& |
| 166 |
\& $ftp\->quit; |
| 167 |
.Ve |
| 168 |
.SS "How do I transfer files in binary mode ?" |
| 169 |
.IX Subsection "How do I transfer files in binary mode ?" |
| 170 |
To transfer files without <LF><CR> translation Net::FTP provides |
| 171 |
the \f(CW\*(C`binary\*(C'\fR method |
| 172 |
.PP |
| 173 |
.Vb 1 |
| 174 |
\& $ftp\->binary; |
| 175 |
.Ve |
| 176 |
.SS "How can I get the size of a file on a remote FTP server ?" |
| 177 |
.IX Subsection "How can I get the size of a file on a remote FTP server ?" |
| 178 |
.SS "How can I get the modification time of a file on a remote FTP server ?" |
| 179 |
.IX Subsection "How can I get the modification time of a file on a remote FTP server ?" |
| 180 |
.SS "How can I change the permissions of a file on a remote server ?" |
| 181 |
.IX Subsection "How can I change the permissions of a file on a remote server ?" |
| 182 |
The FTP protocol does not have a command for changing the permissions |
| 183 |
of a file on the remote server. But some ftp servers may allow a chmod |
| 184 |
command to be issued via a SITE command, eg |
| 185 |
.PP |
| 186 |
.Vb 1 |
| 187 |
\& $ftp\->quot(\*(Aqsite chmod 0777\*(Aq,$filename); |
| 188 |
.Ve |
| 189 |
.PP |
| 190 |
But this is not guaranteed to work. |
| 191 |
.SS "Can I do a reget operation like the ftp command ?" |
| 192 |
.IX Subsection "Can I do a reget operation like the ftp command ?" |
| 193 |
.SS "How do I get a directory listing from an FTP server ?" |
| 194 |
.IX Subsection "How do I get a directory listing from an FTP server ?" |
| 195 |
.SS "Changing directory to """" does not fail ?" |
| 196 |
.IX Subsection "Changing directory to """" does not fail ?" |
| 197 |
Passing an argument of "" to \->\fBcwd()\fR has the same affect of calling \->\fBcwd()\fR |
| 198 |
without any arguments. Turn on Debug (\fISee below\fR) and you will see what is |
| 199 |
happening |
| 200 |
.PP |
| 201 |
.Vb 3 |
| 202 |
\& $ftp = Net::FTP\->new($host, Debug => 1); |
| 203 |
\& $ftp\->login; |
| 204 |
\& $ftp\->cwd(""); |
| 205 |
.Ve |
| 206 |
.PP |
| 207 |
gives |
| 208 |
.PP |
| 209 |
.Vb 2 |
| 210 |
\& Net::FTP=GLOB(0x82196d8)>>> CWD / |
| 211 |
\& Net::FTP=GLOB(0x82196d8)<<< 250 CWD command successful. |
| 212 |
.Ve |
| 213 |
.SS "I am behind a SOCKS firewall, but the Firewall option does not work ?" |
| 214 |
.IX Subsection "I am behind a SOCKS firewall, but the Firewall option does not work ?" |
| 215 |
The Firewall option is only for support of one type of firewall. The type |
| 216 |
supported is an ftp proxy. |
| 217 |
.PP |
| 218 |
To use Net::FTP, or any other module in the libnet distribution, |
| 219 |
through a SOCKS firewall you must create a socks-ified perl executable |
| 220 |
by compiling perl with the socks library. |
| 221 |
.SS "I am behind an FTP proxy firewall, but cannot access machines outside ?" |
| 222 |
.IX Subsection "I am behind an FTP proxy firewall, but cannot access machines outside ?" |
| 223 |
Net::FTP implements the most popular ftp proxy firewall approach. The scheme |
| 224 |
implemented is that where you log in to the firewall with \f(CW\*(C`user@hostname\*(C'\fR |
| 225 |
.PP |
| 226 |
I have heard of one other type of firewall which requires a login to the |
| 227 |
firewall with an account, then a second login with \f(CW\*(C`user@hostname\*(C'\fR. You can |
| 228 |
still use Net::FTP to traverse these firewalls, but a more manual approach |
| 229 |
must be taken, eg |
| 230 |
.PP |
| 231 |
.Vb 3 |
| 232 |
\& $ftp = Net::FTP\->new($firewall) or die $@; |
| 233 |
\& $ftp\->login($firewall_user, $firewall_passwd) or die $ftp\->message; |
| 234 |
\& $ftp\->login($ext_user . \*(Aq@\*(Aq . $ext_host, $ext_passwd) or die $ftp\->message. |
| 235 |
.Ve |
| 236 |
.SS "My ftp proxy firewall does not listen on port 21" |
| 237 |
.IX Subsection "My ftp proxy firewall does not listen on port 21" |
| 238 |
FTP servers usually listen on the same port number, port 21, as any other |
| 239 |
FTP server. But there is no reason why this has to be the case. |
| 240 |
.PP |
| 241 |
If you pass a port number to Net::FTP then it assumes this is the port |
| 242 |
number of the final destination. By default Net::FTP will always try |
| 243 |
to connect to the firewall on port 21. |
| 244 |
.PP |
| 245 |
Net::FTP uses IO::Socket to open the connection and IO::Socket allows |
| 246 |
the port number to be specified as part of the hostname. So this problem |
| 247 |
can be resolved by either passing a Firewall option like \f(CW"hostname:1234"\fR |
| 248 |
or by setting the \f(CW\*(C`ftp_firewall\*(C'\fR option in Net::Config to be a string |
| 249 |
in the same form. |
| 250 |
.SS "Is it possible to change the file permissions of a file on an FTP server ?" |
| 251 |
.IX Subsection "Is it possible to change the file permissions of a file on an FTP server ?" |
| 252 |
The answer to this is "maybe". The FTP protocol does not specify a command to change |
| 253 |
file permissions on a remote host. However many servers do allow you to run the |
| 254 |
chmod command via the \f(CW\*(C`SITE\*(C'\fR command. This can be done with |
| 255 |
.PP |
| 256 |
.Vb 1 |
| 257 |
\& $ftp\->site(\*(Aqchmod\*(Aq,\*(Aq0775\*(Aq,$file); |
| 258 |
.Ve |
| 259 |
.SS "I have seen scripts call a method message, but cannot find it documented ?" |
| 260 |
.IX Subsection "I have seen scripts call a method message, but cannot find it documented ?" |
| 261 |
Net::FTP, like several other packages in libnet, inherits from Net::Cmd, so |
| 262 |
all the methods described in Net::Cmd are also available on Net::FTP |
| 263 |
objects. |
| 264 |
.SS "Why does Net::FTP not implement mput and mget methods" |
| 265 |
.IX Subsection "Why does Net::FTP not implement mput and mget methods" |
| 266 |
The quick answer is because they are easy to implement yourself. The long |
| 267 |
answer is that to write these in such a way that multiple platforms are |
| 268 |
supported correctly would just require too much code. Below are |
| 269 |
some examples how you can implement these yourself. |
| 270 |
.PP |
| 271 |
sub mput { |
| 272 |
my($ftp,$pattern) = \f(CW@_\fR; |
| 273 |
foreach my \f(CW$file\fR (glob($pattern)) { |
| 274 |
\f(CW$ftp\fR\->put($file) or warn \f(CW$ftp\fR\->message; |
| 275 |
} |
| 276 |
} |
| 277 |
.PP |
| 278 |
sub mget { |
| 279 |
my($ftp,$pattern) = \f(CW@_\fR; |
| 280 |
foreach my \f(CW$file\fR ($ftp\->ls($pattern)) { |
| 281 |
\f(CW$ftp\fR\->get($file) or warn \f(CW$ftp\fR\->message; |
| 282 |
} |
| 283 |
} |
| 284 |
.SH "Using Net::SMTP" |
| 285 |
.IX Header "Using Net::SMTP" |
| 286 |
.SS "Why can't the part of an Email address after the @ be used as the hostname ?" |
| 287 |
.IX Subsection "Why can't the part of an Email address after the @ be used as the hostname ?" |
| 288 |
The part of an Email address which follows the @ is not necessarily a hostname, |
| 289 |
it is a mail domain. To find the name of a host to connect for a mail domain |
| 290 |
you need to do a DNS MX lookup |
| 291 |
.SS "Why does Net::SMTP not do DNS MX lookups ?" |
| 292 |
.IX Subsection "Why does Net::SMTP not do DNS MX lookups ?" |
| 293 |
Net::SMTP implements the SMTP protocol. The DNS MX lookup is not part |
| 294 |
of this protocol. |
| 295 |
.SS "The verify method always returns true ?" |
| 296 |
.IX Subsection "The verify method always returns true ?" |
| 297 |
Well it may seem that way, but it does not. The verify method returns true |
| 298 |
if the command succeeded. If you pass verify an address which the |
| 299 |
server would normally have to forward to another machine, the command |
| 300 |
will succeed with something like |
| 301 |
.PP |
| 302 |
.Vb 1 |
| 303 |
\& 252 Couldn\*(Aqt verify <someone@there> but will attempt delivery anyway |
| 304 |
.Ve |
| 305 |
.PP |
| 306 |
This command will fail only if you pass it an address in a domain |
| 307 |
the server directly delivers for, and that address does not exist. |
| 308 |
.SH "Debugging scripts" |
| 309 |
.IX Header "Debugging scripts" |
| 310 |
.SS "How can I debug my scripts that use Net::* modules ?" |
| 311 |
.IX Subsection "How can I debug my scripts that use Net::* modules ?" |
| 312 |
Most of the libnet client classes allow options to be passed to the |
| 313 |
constructor, in most cases one option is called \f(CW\*(C`Debug\*(C'\fR. Passing |
| 314 |
this option with a non-zero value will turn on a protocol trace, which |
| 315 |
will be sent to STDERR. This trace can be useful to see what commands |
| 316 |
are being sent to the remote server and what responses are being |
| 317 |
received back. |
| 318 |
.PP |
| 319 |
.Vb 1 |
| 320 |
\& #!/your/path/to/perl |
| 321 |
\& |
| 322 |
\& use Net::FTP; |
| 323 |
\& |
| 324 |
\& my $ftp = new Net::FTP($host, Debug => 1); |
| 325 |
\& $ftp\->login(\*(Aqgbarr\*(Aq,\*(Aqpassword\*(Aq); |
| 326 |
\& $ftp\->quit; |
| 327 |
.Ve |
| 328 |
.PP |
| 329 |
this script would output something like |
| 330 |
.PP |
| 331 |
.Vb 6 |
| 332 |
\& Net::FTP: Net::FTP(2.22) |
| 333 |
\& Net::FTP: Exporter |
| 334 |
\& Net::FTP: Net::Cmd(2.0801) |
| 335 |
\& Net::FTP: IO::Socket::INET |
| 336 |
\& Net::FTP: IO::Socket(1.1603) |
| 337 |
\& Net::FTP: IO::Handle(1.1504) |
| 338 |
\& |
| 339 |
\& Net::FTP=GLOB(0x8152974)<<< 220 imagine FTP server (Version wu\-2.4(5) Tue Jul 29 11:17:18 CDT 1997) ready. |
| 340 |
\& Net::FTP=GLOB(0x8152974)>>> user gbarr |
| 341 |
\& Net::FTP=GLOB(0x8152974)<<< 331 Password required for gbarr. |
| 342 |
\& Net::FTP=GLOB(0x8152974)>>> PASS .... |
| 343 |
\& Net::FTP=GLOB(0x8152974)<<< 230 User gbarr logged in. Access restrictions apply. |
| 344 |
\& Net::FTP=GLOB(0x8152974)>>> QUIT |
| 345 |
\& Net::FTP=GLOB(0x8152974)<<< 221 Goodbye. |
| 346 |
.Ve |
| 347 |
.PP |
| 348 |
The first few lines tell you the modules that Net::FTP uses and their versions, |
| 349 |
this is useful data to me when a user reports a bug. The last seven lines |
| 350 |
show the communication with the server. Each line has three parts. The first |
| 351 |
part is the object itself, this is useful for separating the output |
| 352 |
if you are using multiple objects. The second part is either \f(CW\*(C`<<<<\*(C'\fR to |
| 353 |
show data coming from the server or \f(CW\*(C`>>>>\*(C'\fR to show data |
| 354 |
going to the server. The remainder of the line is the command |
| 355 |
being sent or response being received. |
| 356 |
.SH "AUTHOR AND COPYRIGHT" |
| 357 |
.IX Header "AUTHOR AND COPYRIGHT" |
| 358 |
Copyright (C) 1997\-1998 Graham Barr. All rights reserved. |