Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
10 KiB

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