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.

1642 lines
40 KiB

  1. # Net::FTP.pm
  2. #
  3. # Copyright (c) 1995-8 Graham Barr <[email protected]>. All rights reserved.
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the same terms as Perl itself.
  6. #
  7. # Documentation (at end) improved 1996 by Nathan Torkington <[email protected]>.
  8. package Net::FTP;
  9. require 5.001;
  10. use strict;
  11. use vars qw(@ISA $VERSION);
  12. use Carp;
  13. use Socket 1.3;
  14. use IO::Socket;
  15. use Time::Local;
  16. use Net::Cmd;
  17. use Net::Config;
  18. # use AutoLoader qw(AUTOLOAD);
  19. $VERSION = "2.56"; # $Id:$
  20. @ISA = qw(Exporter Net::Cmd IO::Socket::INET);
  21. # Someday I will "use constant", when I am not bothered to much about
  22. # compatability with older releases of perl
  23. use vars qw($TELNET_IAC $TELNET_IP $TELNET_DM);
  24. ($TELNET_IAC,$TELNET_IP,$TELNET_DM) = (255,244,242);
  25. # Name is too long for AutoLoad, it clashes with pasv_xfer
  26. sub pasv_xfer_unique {
  27. my($sftp,$sfile,$dftp,$dfile) = @_;
  28. $sftp->pasv_xfer($sfile,$dftp,$dfile,1);
  29. }
  30. 1;
  31. # Having problems with AutoLoader
  32. #__END__
  33. sub new
  34. {
  35. my $pkg = shift;
  36. my $peer = shift;
  37. my %arg = @_;
  38. my $host = $peer;
  39. my $fire = undef;
  40. if(exists($arg{Firewall}) || Net::Config->requires_firewall($peer))
  41. {
  42. $fire = $arg{Firewall}
  43. || $ENV{FTP_FIREWALL}
  44. || $NetConfig{ftp_firewall}
  45. || undef;
  46. if(defined $fire)
  47. {
  48. $peer = $fire;
  49. delete $arg{Port};
  50. }
  51. }
  52. my $ftp = $pkg->SUPER::new(PeerAddr => $peer,
  53. PeerPort => $arg{Port} || 'ftp(21)',
  54. Proto => 'tcp',
  55. Timeout => defined $arg{Timeout}
  56. ? $arg{Timeout}
  57. : 120
  58. ) or return undef;
  59. ${*$ftp}{'net_ftp_host'} = $host; # Remote hostname
  60. ${*$ftp}{'net_ftp_type'} = 'A'; # ASCII/binary/etc mode
  61. ${*$ftp}{'net_ftp_blksize'} = abs($arg{'BlockSize'} || 10240);
  62. ${*$ftp}{'net_ftp_firewall'} = $fire
  63. if(defined $fire);
  64. ${*$ftp}{'net_ftp_passive'} = int
  65. exists $arg{Passive}
  66. ? $arg{Passive}
  67. : exists $ENV{FTP_PASSIVE}
  68. ? $ENV{FTP_PASSIVE}
  69. : defined $fire
  70. ? $NetConfig{ftp_ext_passive}
  71. : $NetConfig{ftp_int_passive}; # Whew! :-)
  72. $ftp->hash(exists $arg{Hash} ? $arg{Hash} : 0, 1024);
  73. $ftp->autoflush(1);
  74. $ftp->debug(exists $arg{Debug} ? $arg{Debug} : undef);
  75. unless ($ftp->response() == CMD_OK)
  76. {
  77. $ftp->close();
  78. $@ = $ftp->message;
  79. undef $ftp;
  80. }
  81. $ftp;
  82. }
  83. ##
  84. ## User interface methods
  85. ##
  86. sub hash {
  87. my $ftp = shift; # self
  88. my $prev = ${*$ftp}{'net_ftp_hash'} || [\*STDERR, 0];
  89. unless(@_) {
  90. return $prev;
  91. }
  92. my($h,$b) = @_;
  93. if(@_ == 1) {
  94. unless($h) {
  95. delete ${*$ftp}{'net_ftp_hash'};
  96. return $prev;
  97. }
  98. elsif(ref($h)) {
  99. $b = 1024;
  100. }
  101. else {
  102. ($h,$b) = (\*STDERR,$h);
  103. }
  104. }
  105. select((select($h), $|=1)[0]);
  106. $b = 512 if $b < 512;
  107. ${*$ftp}{'net_ftp_hash'} = [$h, $b];
  108. $prev;
  109. }
  110. sub quit
  111. {
  112. my $ftp = shift;
  113. $ftp->_QUIT;
  114. $ftp->close;
  115. }
  116. sub DESTROY
  117. {
  118. my $ftp = shift;
  119. defined(fileno($ftp)) && $ftp->quit
  120. }
  121. sub ascii { shift->type('A',@_); }
  122. sub binary { shift->type('I',@_); }
  123. sub ebcdic
  124. {
  125. carp "TYPE E is unsupported, shall default to I";
  126. shift->type('E',@_);
  127. }
  128. sub byte
  129. {
  130. carp "TYPE L is unsupported, shall default to I";
  131. shift->type('L',@_);
  132. }
  133. # Allow the user to send a command directly, BE CAREFUL !!
  134. sub quot
  135. {
  136. my $ftp = shift;
  137. my $cmd = shift;
  138. $ftp->command( uc $cmd, @_);
  139. $ftp->response();
  140. }
  141. sub site
  142. {
  143. my $ftp = shift;
  144. $ftp->command("SITE", @_);
  145. $ftp->response();
  146. }
  147. sub mdtm
  148. {
  149. my $ftp = shift;
  150. my $file = shift;
  151. # Server Y2K bug workaround
  152. #
  153. # sigh; some idiotic FTP servers use ("19%d",tm.tm_year) instead of
  154. # ("%d",tm.tm_year+1900). This results in an extra digit in the
  155. # string returned. To account for this we allow an optional extra
  156. # digit in the year. Then if the first two digits are 19 we use the
  157. # remainder, otherwise we subtract 1900 from the whole year.
  158. $ftp->_MDTM($file) && $ftp->message =~ /((\d\d)(\d\d\d?))(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
  159. ? timegm($8,$7,$6,$5,$4-1,$2 eq '19' ? $3 : ($1-1900))
  160. : undef;
  161. }
  162. sub size {
  163. my $ftp = shift;
  164. my $file = shift;
  165. my $io;
  166. if($ftp->supported("SIZE")) {
  167. return $ftp->_SIZE($file)
  168. ? ($ftp->message =~ /(\d+)/)[0]
  169. : undef;
  170. }
  171. elsif($ftp->supported("STAT")) {
  172. my @msg;
  173. return undef
  174. unless $ftp->_STAT($file) && (@msg = $ftp->message) == 3;
  175. my $line;
  176. foreach $line (@msg) {
  177. return (split(/\s+/,$line))[4]
  178. if $line =~ /^[-rw]{10}/
  179. }
  180. }
  181. else {
  182. my @files = $ftp->dir($file);
  183. if(@files) {
  184. return (split(/\s+/,$1))[4]
  185. if $files[0] =~ /^([-rw]{10}.*)$/;
  186. }
  187. }
  188. undef;
  189. }
  190. sub login {
  191. my($ftp,$user,$pass,$acct) = @_;
  192. my($ok,$ruser,$fwtype);
  193. unless (defined $user) {
  194. require Net::Netrc;
  195. my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'});
  196. ($user,$pass,$acct) = $rc->lpa()
  197. if ($rc);
  198. }
  199. $user ||= "anonymous";
  200. $ruser = $user;
  201. $fwtype = $NetConfig{'ftp_firewall_type'} || 0;
  202. if ($fwtype && defined ${*$ftp}{'net_ftp_firewall'}) {
  203. if ($fwtype == 1 || $fwtype == 7) {
  204. $user .= '@' . ${*$ftp}{'net_ftp_host'};
  205. }
  206. else {
  207. require Net::Netrc;
  208. my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
  209. my($fwuser,$fwpass,$fwacct) = $rc ? $rc->lpa() : ();
  210. if ($fwtype == 5) {
  211. $user = join('@',$user,$fwuser,${*$ftp}{'net_ftp_host'});
  212. $pass = $pass . '@' . $fwpass;
  213. }
  214. else {
  215. if ($fwtype == 2) {
  216. $user .= '@' . ${*$ftp}{'net_ftp_host'};
  217. }
  218. elsif ($fwtype == 6) {
  219. $fwuser .= '@' . ${*$ftp}{'net_ftp_host'};
  220. }
  221. $ok = $ftp->_USER($fwuser);
  222. return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
  223. $ok = $ftp->_PASS($fwpass || "");
  224. return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
  225. $ok = $ftp->_ACCT($fwacct)
  226. if defined($fwacct);
  227. if ($fwtype == 3) {
  228. $ok = $ftp->command("SITE",${*$ftp}{'net_ftp_host'})->response;
  229. }
  230. elsif ($fwtype == 4) {
  231. $ok = $ftp->command("OPEN",${*$ftp}{'net_ftp_host'})->response;
  232. }
  233. return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
  234. }
  235. }
  236. }
  237. $ok = $ftp->_USER($user);
  238. # Some dumb firewalls don't prefix the connection messages
  239. $ok = $ftp->response()
  240. if ($ok == CMD_OK && $ftp->code == 220 && $user =~ /\@/);
  241. if ($ok == CMD_MORE) {
  242. unless(defined $pass) {
  243. require Net::Netrc;
  244. my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'}, $ruser);
  245. ($ruser,$pass,$acct) = $rc->lpa()
  246. if ($rc);
  247. $pass = "-" . (eval { (getpwuid($>))[0] } || $ENV{NAME} ) . '@'
  248. if (!defined $pass && (!defined($ruser) || $ruser =~ /^anonymous/o));
  249. }
  250. $ok = $ftp->_PASS($pass || "");
  251. }
  252. $ok = $ftp->_ACCT($acct)
  253. if (defined($acct) && ($ok == CMD_MORE || $ok == CMD_OK));
  254. if ($fwtype == 7 && $ok == CMD_OK && defined ${*$ftp}{'net_ftp_firewall'}) {
  255. my($f,$auth,$resp) = _auth_id($ftp);
  256. $ftp->authorize($auth,$resp) if defined($resp);
  257. }
  258. $ok == CMD_OK;
  259. }
  260. sub account
  261. {
  262. @_ == 2 or croak 'usage: $ftp->account( ACCT )';
  263. my $ftp = shift;
  264. my $acct = shift;
  265. $ftp->_ACCT($acct) == CMD_OK;
  266. }
  267. sub _auth_id {
  268. my($ftp,$auth,$resp) = @_;
  269. unless(defined $resp)
  270. {
  271. require Net::Netrc;
  272. $auth ||= eval { (getpwuid($>))[0] } || $ENV{NAME};
  273. my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'}, $auth)
  274. || Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
  275. ($auth,$resp) = $rc->lpa()
  276. if ($rc);
  277. }
  278. ($ftp,$auth,$resp);
  279. }
  280. sub authorize
  281. {
  282. @_ >= 1 || @_ <= 3 or croak 'usage: $ftp->authorize( [AUTH [, RESP]])';
  283. my($ftp,$auth,$resp) = &_auth_id;
  284. my $ok = $ftp->_AUTH($auth || "");
  285. $ok = $ftp->_RESP($resp || "")
  286. if ($ok == CMD_MORE);
  287. $ok == CMD_OK;
  288. }
  289. sub rename
  290. {
  291. @_ == 3 or croak 'usage: $ftp->rename(FROM, TO)';
  292. my($ftp,$from,$to) = @_;
  293. $ftp->_RNFR($from)
  294. && $ftp->_RNTO($to);
  295. }
  296. sub type
  297. {
  298. my $ftp = shift;
  299. my $type = shift;
  300. my $oldval = ${*$ftp}{'net_ftp_type'};
  301. return $oldval
  302. unless (defined $type);
  303. return undef
  304. unless ($ftp->_TYPE($type,@_));
  305. ${*$ftp}{'net_ftp_type'} = join(" ",$type,@_);
  306. $oldval;
  307. }
  308. sub abort
  309. {
  310. my $ftp = shift;
  311. send($ftp,pack("CCC", $TELNET_IAC, $TELNET_IP, $TELNET_IAC),MSG_OOB);
  312. $ftp->command(pack("C",$TELNET_DM) . "ABOR");
  313. ${*$ftp}{'net_ftp_dataconn'}->close()
  314. if defined ${*$ftp}{'net_ftp_dataconn'};
  315. $ftp->response();
  316. $ftp->status == CMD_OK;
  317. }
  318. sub get
  319. {
  320. my($ftp,$remote,$local,$where) = @_;
  321. my($loc,$len,$buf,$resp,$localfd,$data);
  322. local *FD;
  323. $localfd = ref($local) || ref(\$local) eq "GLOB"
  324. ? fileno($local)
  325. : undef;
  326. ($local = $remote) =~ s#^.*/##
  327. unless(defined $local);
  328. croak("Bad remote filename '$remote'\n")
  329. if $remote =~ /[\r\n]/s;
  330. ${*$ftp}{'net_ftp_rest'} = $where
  331. if ($where);
  332. delete ${*$ftp}{'net_ftp_port'};
  333. delete ${*$ftp}{'net_ftp_pasv'};
  334. $data = $ftp->retr($remote) or
  335. return undef;
  336. if(defined $localfd)
  337. {
  338. $loc = $local;
  339. }
  340. else
  341. {
  342. $loc = \*FD;
  343. unless(($where) ? open($loc,">>$local") : open($loc,">$local"))
  344. {
  345. carp "Cannot open Local file $local: $!\n";
  346. $data->abort;
  347. return undef;
  348. }
  349. }
  350. if($ftp->type eq 'I' && !binmode($loc))
  351. {
  352. carp "Cannot binmode Local file $local: $!\n";
  353. $data->abort;
  354. close($loc) unless $localfd;
  355. return undef;
  356. }
  357. $buf = '';
  358. my($count,$hashh,$hashb,$ref) = (0);
  359. ($hashh,$hashb) = @$ref
  360. if($ref = ${*$ftp}{'net_ftp_hash'});
  361. my $blksize = ${*$ftp}{'net_ftp_blksize'};
  362. while(1)
  363. {
  364. last unless $len = $data->read($buf,$blksize);
  365. if($hashh) {
  366. $count += $len;
  367. print $hashh "#" x (int($count / $hashb));
  368. $count %= $hashb;
  369. }
  370. my $written = syswrite($loc,$buf,$len);
  371. unless(defined($written) && $written == $len)
  372. {
  373. carp "Cannot write to Local file $local: $!\n";
  374. $data->abort;
  375. close($loc)
  376. unless defined $localfd;
  377. return undef;
  378. }
  379. }
  380. print $hashh "\n" if $hashh;
  381. close($loc)
  382. unless defined $localfd;
  383. $data->close(); # implied $ftp->response
  384. return $local;
  385. }
  386. sub cwd
  387. {
  388. @_ == 1 || @_ == 2 or croak 'usage: $ftp->cwd( [ DIR ] )';
  389. my($ftp,$dir) = @_;
  390. $dir = "/" unless defined($dir) && $dir =~ /\S/;
  391. $dir eq ".."
  392. ? $ftp->_CDUP()
  393. : $ftp->_CWD($dir);
  394. }
  395. sub cdup
  396. {
  397. @_ == 1 or croak 'usage: $ftp->cdup()';
  398. $_[0]->_CDUP;
  399. }
  400. sub pwd
  401. {
  402. @_ == 1 || croak 'usage: $ftp->pwd()';
  403. my $ftp = shift;
  404. $ftp->_PWD();
  405. $ftp->_extract_path;
  406. }
  407. # rmdir( $ftp, $dir, [ $recurse ] )
  408. #
  409. # Removes $dir on remote host via FTP.
  410. # $ftp is handle for remote host
  411. #
  412. # If $recurse is TRUE, the directory and deleted recursively.
  413. # This means all of its contents and subdirectories.
  414. #
  415. # Initial version contributed by Dinkum Software
  416. #
  417. sub rmdir
  418. {
  419. @_ == 2 || @_ == 3 or croak('usage: $ftp->rmdir( DIR [, RECURSE ] )');
  420. # Pick off the args
  421. my ($ftp, $dir, $recurse) = @_ ;
  422. my $ok;
  423. return $ok
  424. if $ftp->_RMD( $dir ) || !$recurse;
  425. # Try to delete the contents
  426. # Get a list of all the files in the directory
  427. my $filelist = $ftp->ls($dir);
  428. return undef
  429. unless $filelist && @$filelist; # failed, it is probably not a directory
  430. # Go thru and delete each file or the directory
  431. my $file;
  432. foreach $file (map { m,/, ? $_ : "$dir/$_" } @$filelist)
  433. {
  434. next # successfully deleted the file
  435. if $ftp->delete($file);
  436. # Failed to delete it, assume its a directory
  437. # Recurse and ignore errors, the final rmdir() will
  438. # fail on any errors here
  439. return $ok
  440. unless $ok = $ftp->rmdir($file, 1) ;
  441. }
  442. # Directory should be empty
  443. # Try to remove the directory again
  444. # Pass results directly to caller
  445. # If any of the prior deletes failed, this
  446. # rmdir() will fail because directory is not empty
  447. return $ftp->_RMD($dir) ;
  448. }
  449. sub mkdir
  450. {
  451. @_ == 2 || @_ == 3 or croak 'usage: $ftp->mkdir( DIR [, RECURSE ] )';
  452. my($ftp,$dir,$recurse) = @_;
  453. $ftp->_MKD($dir) || $recurse or
  454. return undef;
  455. my $path = $dir;
  456. unless($ftp->ok)
  457. {
  458. my @path = split(m#(?=/+)#, $dir);
  459. $path = "";
  460. while(@path)
  461. {
  462. $path .= shift @path;
  463. $ftp->_MKD($path);
  464. $path = $ftp->_extract_path($path);
  465. }
  466. # If the creation of the last element was not sucessful, see if we
  467. # can cd to it, if so then return path
  468. unless($ftp->ok)
  469. {
  470. my($status,$message) = ($ftp->status,$ftp->message);
  471. my $pwd = $ftp->pwd;
  472. if($pwd && $ftp->cwd($dir))
  473. {
  474. $path = $dir;
  475. $ftp->cwd($pwd);
  476. }
  477. else
  478. {
  479. undef $path;
  480. }
  481. $ftp->set_status($status,$message);
  482. }
  483. }
  484. $path;
  485. }
  486. sub delete
  487. {
  488. @_ == 2 || croak 'usage: $ftp->delete( FILENAME )';
  489. $_[0]->_DELE($_[1]);
  490. }
  491. sub put { shift->_store_cmd("stor",@_) }
  492. sub put_unique { shift->_store_cmd("stou",@_) }
  493. sub append { shift->_store_cmd("appe",@_) }
  494. sub nlst { shift->_data_cmd("NLST",@_) }
  495. sub list { shift->_data_cmd("LIST",@_) }
  496. sub retr { shift->_data_cmd("RETR",@_) }
  497. sub stor { shift->_data_cmd("STOR",@_) }
  498. sub stou { shift->_data_cmd("STOU",@_) }
  499. sub appe { shift->_data_cmd("APPE",@_) }
  500. sub _store_cmd
  501. {
  502. my($ftp,$cmd,$local,$remote) = @_;
  503. my($loc,$sock,$len,$buf,$localfd);
  504. local *FD;
  505. $localfd = ref($local) || ref(\$local) eq "GLOB"
  506. ? fileno($local)
  507. : undef;
  508. unless(defined $remote)
  509. {
  510. croak 'Must specify remote filename with stream input'
  511. if defined $localfd;
  512. require File::Basename;
  513. $remote = File::Basename::basename($local);
  514. }
  515. croak("Bad remote filename '$remote'\n")
  516. if $remote =~ /[\r\n]/s;
  517. if(defined $localfd)
  518. {
  519. $loc = $local;
  520. }
  521. else
  522. {
  523. $loc = \*FD;
  524. unless(open($loc,"<$local"))
  525. {
  526. carp "Cannot open Local file $local: $!\n";
  527. return undef;
  528. }
  529. }
  530. if($ftp->type eq 'I' && !binmode($loc))
  531. {
  532. carp "Cannot binmode Local file $local: $!\n";
  533. return undef;
  534. }
  535. delete ${*$ftp}{'net_ftp_port'};
  536. delete ${*$ftp}{'net_ftp_pasv'};
  537. $sock = $ftp->_data_cmd($cmd, $remote) or
  538. return undef;
  539. my $blksize = ${*$ftp}{'net_ftp_blksize'};
  540. my($count,$hashh,$hashb,$ref) = (0);
  541. ($hashh,$hashb) = @$ref
  542. if($ref = ${*$ftp}{'net_ftp_hash'});
  543. while(1)
  544. {
  545. last unless $len = sysread($loc,$buf="",$blksize);
  546. if($hashh) {
  547. $count += $len;
  548. print $hashh "#" x (int($count / $hashb));
  549. $count %= $hashb;
  550. }
  551. my $wlen;
  552. unless(defined($wlen = $sock->write($buf,$len)) && $wlen == $len)
  553. {
  554. $sock->abort;
  555. close($loc)
  556. unless defined $localfd;
  557. print $hashh "\n" if $hashh;
  558. return undef;
  559. }
  560. }
  561. print $hashh "\n" if $hashh;
  562. close($loc)
  563. unless defined $localfd;
  564. $sock->close() or
  565. return undef;
  566. ($remote) = $ftp->message =~ /unique file name:\s*(\S*)\s*\)/
  567. if ('STOU' eq uc $cmd);
  568. return $remote;
  569. }
  570. sub port
  571. {
  572. @_ == 1 || @_ == 2 or croak 'usage: $ftp->port([PORT])';
  573. my($ftp,$port) = @_;
  574. my $ok;
  575. delete ${*$ftp}{'net_ftp_intern_port'};
  576. unless(defined $port)
  577. {
  578. # create a Listen socket at same address as the command socket
  579. ${*$ftp}{'net_ftp_listen'} ||= IO::Socket::INET->new(Listen => 5,
  580. Proto => 'tcp',
  581. );
  582. my $listen = ${*$ftp}{'net_ftp_listen'};
  583. my($myport, @myaddr) = ($listen->sockport, split(/\./,$ftp->sockhost));
  584. $port = join(',', @myaddr, $myport >> 8, $myport & 0xff);
  585. ${*$ftp}{'net_ftp_intern_port'} = 1;
  586. }
  587. $ok = $ftp->_PORT($port);
  588. ${*$ftp}{'net_ftp_port'} = $port;
  589. $ok;
  590. }
  591. sub ls { shift->_list_cmd("NLST",@_); }
  592. sub dir { shift->_list_cmd("LIST",@_); }
  593. sub pasv
  594. {
  595. @_ == 1 or croak 'usage: $ftp->pasv()';
  596. my $ftp = shift;
  597. delete ${*$ftp}{'net_ftp_intern_port'};
  598. $ftp->_PASV && $ftp->message =~ /(\d+(,\d+)+)/
  599. ? ${*$ftp}{'net_ftp_pasv'} = $1
  600. : undef;
  601. }
  602. sub unique_name
  603. {
  604. my $ftp = shift;
  605. ${*$ftp}{'net_ftp_unique'} || undef;
  606. }
  607. sub supported {
  608. @_ == 2 or croak 'usage: $ftp->supported( CMD )';
  609. my $ftp = shift;
  610. my $cmd = uc shift;
  611. my $hash = ${*$ftp}{'net_ftp_supported'} ||= {};
  612. return $hash->{$cmd}
  613. if exists $hash->{$cmd};
  614. return $hash->{$cmd} = 0
  615. unless $ftp->_HELP($cmd);
  616. my $text = $ftp->message;
  617. if($text =~ /following\s+commands/i) {
  618. $text =~ s/^.*\n//;
  619. $text =~ s/\n/ /sog;
  620. while($text =~ /(\w+)([* ])/g) {
  621. $hash->{"\U$1"} = $2 eq " " ? 1 : 0;
  622. }
  623. }
  624. else {
  625. $hash->{$cmd} = $text !~ /unimplemented/i;
  626. }
  627. $hash->{$cmd} ||= 0;
  628. }
  629. ##
  630. ## Deprecated methods
  631. ##
  632. sub lsl
  633. {
  634. carp "Use of Net::FTP::lsl deprecated, use 'dir'"
  635. if $^W;
  636. goto &dir;
  637. }
  638. sub authorise
  639. {
  640. carp "Use of Net::FTP::authorise deprecated, use 'authorize'"
  641. if $^W;
  642. goto &authorize;
  643. }
  644. ##
  645. ## Private methods
  646. ##
  647. sub _extract_path
  648. {
  649. my($ftp, $path) = @_;
  650. # This tries to work both with and without the quote doubling
  651. # convention (RFC 959 requires it, but the first 3 servers I checked
  652. # didn't implement it). It will fail on a server which uses a quote in
  653. # the message which isn't a part of or surrounding the path.
  654. $ftp->ok &&
  655. $ftp->message =~ /(?:^|\s)\"(.*)\"(?:$|\s)/ &&
  656. ($path = $1) =~ s/\"\"/\"/g;
  657. $path;
  658. }
  659. ##
  660. ## Communication methods
  661. ##
  662. sub _dataconn
  663. {
  664. my $ftp = shift;
  665. my $data = undef;
  666. my $pkg = "Net::FTP::" . $ftp->type;
  667. eval "require " . $pkg;
  668. $pkg =~ s/ /_/g;
  669. delete ${*$ftp}{'net_ftp_dataconn'};
  670. if(defined ${*$ftp}{'net_ftp_pasv'})
  671. {
  672. my @port = split(/,/,${*$ftp}{'net_ftp_pasv'});
  673. $data = $pkg->new(PeerAddr => join(".",@port[0..3]),
  674. PeerPort => $port[4] * 256 + $port[5],
  675. Proto => 'tcp'
  676. );
  677. }
  678. elsif(defined ${*$ftp}{'net_ftp_listen'})
  679. {
  680. $data = ${*$ftp}{'net_ftp_listen'}->accept($pkg);
  681. close(delete ${*$ftp}{'net_ftp_listen'});
  682. }
  683. if($data)
  684. {
  685. ${*$data} = "";
  686. $data->timeout($ftp->timeout);
  687. ${*$ftp}{'net_ftp_dataconn'} = $data;
  688. ${*$data}{'net_ftp_cmd'} = $ftp;
  689. ${*$data}{'net_ftp_blksize'} = ${*$ftp}{'net_ftp_blksize'};
  690. }
  691. $data;
  692. }
  693. sub _list_cmd
  694. {
  695. my $ftp = shift;
  696. my $cmd = uc shift;
  697. delete ${*$ftp}{'net_ftp_port'};
  698. delete ${*$ftp}{'net_ftp_pasv'};
  699. my $data = $ftp->_data_cmd($cmd,@_);
  700. return
  701. unless(defined $data);
  702. require Net::FTP::A;
  703. bless $data, "Net::FTP::A"; # Force ASCII mode
  704. my $databuf = '';
  705. my $buf = '';
  706. my $blksize = ${*$ftp}{'net_ftp_blksize'};
  707. while($data->read($databuf,$blksize)) {
  708. $buf .= $databuf;
  709. }
  710. my $list = [ split(/\n/,$buf) ];
  711. $data->close();
  712. wantarray ? @{$list}
  713. : $list;
  714. }
  715. sub _data_cmd
  716. {
  717. my $ftp = shift;
  718. my $cmd = uc shift;
  719. my $ok = 1;
  720. my $where = delete ${*$ftp}{'net_ftp_rest'} || 0;
  721. my $arg;
  722. for $arg (@_) {
  723. croak("Bad argument '$arg'\n")
  724. if $arg =~ /[\r\n]/s;
  725. }
  726. if(${*$ftp}{'net_ftp_passive'} &&
  727. !defined ${*$ftp}{'net_ftp_pasv'} &&
  728. !defined ${*$ftp}{'net_ftp_port'})
  729. {
  730. my $data = undef;
  731. $ok = defined $ftp->pasv;
  732. $ok = $ftp->_REST($where)
  733. if $ok && $where;
  734. if($ok)
  735. {
  736. $ftp->command($cmd,@_);
  737. $data = $ftp->_dataconn();
  738. $ok = CMD_INFO == $ftp->response();
  739. if($ok)
  740. {
  741. $data->reading
  742. if $data && $cmd =~ /RETR|LIST|NLST/;
  743. return $data
  744. }
  745. $data->_close
  746. if $data;
  747. }
  748. return undef;
  749. }
  750. $ok = $ftp->port
  751. unless (defined ${*$ftp}{'net_ftp_port'} ||
  752. defined ${*$ftp}{'net_ftp_pasv'});
  753. $ok = $ftp->_REST($where)
  754. if $ok && $where;
  755. return undef
  756. unless $ok;
  757. $ftp->command($cmd,@_);
  758. return 1
  759. if(defined ${*$ftp}{'net_ftp_pasv'});
  760. $ok = CMD_INFO == $ftp->response();
  761. return $ok
  762. unless exists ${*$ftp}{'net_ftp_intern_port'};
  763. if($ok) {
  764. my $data = $ftp->_dataconn();
  765. $data->reading
  766. if $data && $cmd =~ /RETR|LIST|NLST/;
  767. return $data;
  768. }
  769. close(delete ${*$ftp}{'net_ftp_listen'});
  770. return undef;
  771. }
  772. ##
  773. ## Over-ride methods (Net::Cmd)
  774. ##
  775. sub debug_text { $_[2] =~ /^(pass|resp|acct)/i ? "$1 ....\n" : $_[2]; }
  776. sub command
  777. {
  778. my $ftp = shift;
  779. delete ${*$ftp}{'net_ftp_port'};
  780. $ftp->SUPER::command(@_);
  781. }
  782. sub response
  783. {
  784. my $ftp = shift;
  785. my $code = $ftp->SUPER::response();
  786. delete ${*$ftp}{'net_ftp_pasv'}
  787. if ($code != CMD_MORE && $code != CMD_INFO);
  788. $code;
  789. }
  790. sub parse_response
  791. {
  792. return ($1, $2 eq "-")
  793. if $_[1] =~ s/^(\d\d\d)(.?)//o;
  794. my $ftp = shift;
  795. # Darn MS FTP server is a load of CRAP !!!!
  796. return ()
  797. unless ${*$ftp}{'net_cmd_code'} + 0;
  798. (${*$ftp}{'net_cmd_code'},1);
  799. }
  800. ##
  801. ## Allow 2 servers to talk directly
  802. ##
  803. sub pasv_xfer {
  804. my($sftp,$sfile,$dftp,$dfile,$unique) = @_;
  805. ($dfile = $sfile) =~ s#.*/##
  806. unless(defined $dfile);
  807. my $port = $sftp->pasv or
  808. return undef;
  809. $dftp->port($port) or
  810. return undef;
  811. return undef
  812. unless($unique ? $dftp->stou($dfile) : $dftp->stor($dfile));
  813. unless($sftp->retr($sfile) && $sftp->response == CMD_INFO) {
  814. $sftp->retr($sfile);
  815. $dftp->abort;
  816. $dftp->response();
  817. return undef;
  818. }
  819. $dftp->pasv_wait($sftp);
  820. }
  821. sub pasv_wait
  822. {
  823. @_ == 2 or croak 'usage: $ftp->pasv_wait(NON_PASV_FTP)';
  824. my($ftp, $non_pasv) = @_;
  825. my($file,$rin,$rout);
  826. vec($rin='',fileno($ftp),1) = 1;
  827. select($rout=$rin, undef, undef, undef);
  828. $ftp->response();
  829. $non_pasv->response();
  830. return undef
  831. unless $ftp->ok() && $non_pasv->ok();
  832. return $1
  833. if $ftp->message =~ /unique file name:\s*(\S*)\s*\)/;
  834. return $1
  835. if $non_pasv->message =~ /unique file name:\s*(\S*)\s*\)/;
  836. return 1;
  837. }
  838. sub cmd { shift->command(@_)->response() }
  839. ########################################
  840. #
  841. # RFC959 commands
  842. #
  843. sub _ABOR { shift->command("ABOR")->response() == CMD_OK }
  844. sub _CDUP { shift->command("CDUP")->response() == CMD_OK }
  845. sub _NOOP { shift->command("NOOP")->response() == CMD_OK }
  846. sub _PASV { shift->command("PASV")->response() == CMD_OK }
  847. sub _QUIT { shift->command("QUIT")->response() == CMD_OK }
  848. sub _DELE { shift->command("DELE",@_)->response() == CMD_OK }
  849. sub _CWD { shift->command("CWD", @_)->response() == CMD_OK }
  850. sub _PORT { shift->command("PORT",@_)->response() == CMD_OK }
  851. sub _RMD { shift->command("RMD", @_)->response() == CMD_OK }
  852. sub _MKD { shift->command("MKD", @_)->response() == CMD_OK }
  853. sub _PWD { shift->command("PWD", @_)->response() == CMD_OK }
  854. sub _TYPE { shift->command("TYPE",@_)->response() == CMD_OK }
  855. sub _RNTO { shift->command("RNTO",@_)->response() == CMD_OK }
  856. sub _RESP { shift->command("RESP",@_)->response() == CMD_OK }
  857. sub _MDTM { shift->command("MDTM",@_)->response() == CMD_OK }
  858. sub _SIZE { shift->command("SIZE",@_)->response() == CMD_OK }
  859. sub _HELP { shift->command("HELP",@_)->response() == CMD_OK }
  860. sub _STAT { shift->command("STAT",@_)->response() == CMD_OK }
  861. sub _APPE { shift->command("APPE",@_)->response() == CMD_INFO }
  862. sub _LIST { shift->command("LIST",@_)->response() == CMD_INFO }
  863. sub _NLST { shift->command("NLST",@_)->response() == CMD_INFO }
  864. sub _RETR { shift->command("RETR",@_)->response() == CMD_INFO }
  865. sub _STOR { shift->command("STOR",@_)->response() == CMD_INFO }
  866. sub _STOU { shift->command("STOU",@_)->response() == CMD_INFO }
  867. sub _RNFR { shift->command("RNFR",@_)->response() == CMD_MORE }
  868. sub _REST { shift->command("REST",@_)->response() == CMD_MORE }
  869. sub _USER { shift->command("user",@_)->response() } # A certain brain dead firewall :-)
  870. sub _PASS { shift->command("PASS",@_)->response() }
  871. sub _ACCT { shift->command("ACCT",@_)->response() }
  872. sub _AUTH { shift->command("AUTH",@_)->response() }
  873. sub _ALLO { shift->unsupported(@_) }
  874. sub _SMNT { shift->unsupported(@_) }
  875. sub _MODE { shift->unsupported(@_) }
  876. sub _SYST { shift->unsupported(@_) }
  877. sub _STRU { shift->unsupported(@_) }
  878. sub _REIN { shift->unsupported(@_) }
  879. 1;
  880. __END__
  881. =head1 NAME
  882. Net::FTP - FTP Client class
  883. =head1 SYNOPSIS
  884. use Net::FTP;
  885. $ftp = Net::FTP->new("some.host.name", Debug => 0);
  886. $ftp->login("anonymous",'[email protected]');
  887. $ftp->cwd("/pub");
  888. $ftp->get("that.file");
  889. $ftp->quit;
  890. =head1 DESCRIPTION
  891. C<Net::FTP> is a class implementing a simple FTP client in Perl as
  892. described in RFC959. It provides wrappers for a subset of the RFC959
  893. commands.
  894. =head1 OVERVIEW
  895. FTP stands for File Transfer Protocol. It is a way of transferring
  896. files between networked machines. The protocol defines a client
  897. (whose commands are provided by this module) and a server (not
  898. implemented in this module). Communication is always initiated by the
  899. client, and the server responds with a message and a status code (and
  900. sometimes with data).
  901. The FTP protocol allows files to be sent to or fetched from the
  902. server. Each transfer involves a B<local file> (on the client) and a
  903. B<remote file> (on the server). In this module, the same file name
  904. will be used for both local and remote if only one is specified. This
  905. means that transferring remote file C</path/to/file> will try to put
  906. that file in C</path/to/file> locally, unless you specify a local file
  907. name.
  908. The protocol also defines several standard B<translations> which the
  909. file can undergo during transfer. These are ASCII, EBCDIC, binary,
  910. and byte. ASCII is the default type, and indicates that the sender of
  911. files will translate the ends of lines to a standard representation
  912. which the receiver will then translate back into their local
  913. representation. EBCDIC indicates the file being transferred is in
  914. EBCDIC format. Binary (also known as image) format sends the data as
  915. a contiguous bit stream. Byte format transfers the data as bytes, the
  916. values of which remain the same regardless of differences in byte size
  917. between the two machines (in theory - in practice you should only use
  918. this if you really know what you're doing).
  919. =head1 CONSTRUCTOR
  920. =over 4
  921. =item new (HOST [,OPTIONS])
  922. This is the constructor for a new Net::FTP object. C<HOST> is the
  923. name of the remote host to which a FTP connection is required.
  924. C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
  925. Possible options are:
  926. B<Firewall> - The name of a machine which acts as a FTP firewall. This can be
  927. overridden by an environment variable C<FTP_FIREWALL>. If specified, and the
  928. given host cannot be directly connected to, then the
  929. connection is made to the firewall machine and the string C<@hostname> is
  930. appended to the login identifier. This kind of setup is also refered to
  931. as a ftp proxy.
  932. B<BlockSize> - This is the block size that Net::FTP will use when doing
  933. transfers. (defaults to 10240)
  934. B<Port> - The port number to connect to on the remote machine for the
  935. FTP connection
  936. B<Timeout> - Set a timeout value (defaults to 120)
  937. B<Debug> - debug level (see the debug method in L<Net::Cmd>)
  938. B<Passive> - If set to a non-zero value then all data transfers will be done
  939. using passive mode. This is not usually required except for some I<dumb>
  940. servers, and some firewall configurations. This can also be set by the
  941. environment variable C<FTP_PASSIVE>.
  942. B<Hash> - If TRUE, print hash marks (#) on STDERR every 1024 bytes. This
  943. simply invokes the C<hash()> method for you, so that hash marks are displayed
  944. for all transfers. You can, of course, call C<hash()> explicitly whenever
  945. you'd like.
  946. If the constructor fails undef will be returned and an error message will
  947. be in $@
  948. =back
  949. =head1 METHODS
  950. Unless otherwise stated all methods return either a I<true> or I<false>
  951. value, with I<true> meaning that the operation was a success. When a method
  952. states that it returns a value, failure will be returned as I<undef> or an
  953. empty list.
  954. =over 4
  955. =item login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
  956. Log into the remote FTP server with the given login information. If
  957. no arguments are given then the C<Net::FTP> uses the C<Net::Netrc>
  958. package to lookup the login information for the connected host.
  959. If no information is found then a login of I<anonymous> is used.
  960. If no password is given and the login is I<anonymous> then the users
  961. Email address will be used for a password.
  962. If the connection is via a firewall then the C<authorize> method will
  963. be called with no arguments.
  964. =item authorize ( [AUTH [, RESP]])
  965. This is a protocol used by some firewall ftp proxies. It is used
  966. to authorise the user to send data out. If both arguments are not specified
  967. then C<authorize> uses C<Net::Netrc> to do a lookup.
  968. =item site (ARGS)
  969. Send a SITE command to the remote server and wait for a response.
  970. Returns most significant digit of the response code.
  971. =item type (TYPE [, ARGS])
  972. This method will send the TYPE command to the remote FTP server
  973. to change the type of data transfer. The return value is the previous
  974. value.
  975. =item ascii ([ARGS]) binary([ARGS]) ebcdic([ARGS]) byte([ARGS])
  976. Synonyms for C<type> with the first arguments set correctly
  977. B<NOTE> ebcdic and byte are not fully supported.
  978. =item rename ( OLDNAME, NEWNAME )
  979. Rename a file on the remote FTP server from C<OLDNAME> to C<NEWNAME>. This
  980. is done by sending the RNFR and RNTO commands.
  981. =item delete ( FILENAME )
  982. Send a request to the server to delete C<FILENAME>.
  983. =item cwd ( [ DIR ] )
  984. Attempt to change directory to the directory given in C<$dir>. If
  985. C<$dir> is C<"..">, the FTP C<CDUP> command is used to attempt to
  986. move up one directory. If no directory is given then an attempt is made
  987. to change the directory to the root directory.
  988. =item cdup ()
  989. Change directory to the parent of the current directory.
  990. =item pwd ()
  991. Returns the full pathname of the current directory.
  992. =item rmdir ( DIR )
  993. Remove the directory with the name C<DIR>.
  994. =item mkdir ( DIR [, RECURSE ])
  995. Create a new directory with the name C<DIR>. If C<RECURSE> is I<true> then
  996. C<mkdir> will attempt to create all the directories in the given path.
  997. Returns the full pathname to the new directory.
  998. =item ls ( [ DIR ] )
  999. Get a directory listing of C<DIR>, or the current directory.
  1000. In an array context, returns a list of lines returned from the server. In
  1001. a scalar context, returns a reference to a list.
  1002. =item dir ( [ DIR ] )
  1003. Get a directory listing of C<DIR>, or the current directory in long format.
  1004. In an array context, returns a list of lines returned from the server. In
  1005. a scalar context, returns a reference to a list.
  1006. =item get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
  1007. Get C<REMOTE_FILE> from the server and store locally. C<LOCAL_FILE> may be
  1008. a filename or a filehandle. If not specified the the file will be stored in
  1009. the current directory with the same leafname as the remote file.
  1010. If C<WHERE> is given then the first C<WHERE> bytes of the file will
  1011. not be transfered, and the remaining bytes will be appended to
  1012. the local file if it already exists.
  1013. Returns C<LOCAL_FILE>, or the generated local file name if C<LOCAL_FILE>
  1014. is not given.
  1015. =item put ( LOCAL_FILE [, REMOTE_FILE ] )
  1016. Put a file on the remote server. C<LOCAL_FILE> may be a name or a filehandle.
  1017. If C<LOCAL_FILE> is a filehandle then C<REMOTE_FILE> must be specified. If
  1018. C<REMOTE_FILE> is not specified then the file will be stored in the current
  1019. directory with the same leafname as C<LOCAL_FILE>.
  1020. Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
  1021. is not given.
  1022. B<NOTE>: If for some reason the transfer does not complete and an error is
  1023. returned then the contents that had been transfered will not be remove
  1024. automatically.
  1025. =item put_unique ( LOCAL_FILE [, REMOTE_FILE ] )
  1026. Same as put but uses the C<STOU> command.
  1027. Returns the name of the file on the server.
  1028. =item append ( LOCAL_FILE [, REMOTE_FILE ] )
  1029. Same as put but appends to the file on the remote server.
  1030. Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
  1031. is not given.
  1032. =item unique_name ()
  1033. Returns the name of the last file stored on the server using the
  1034. C<STOU> command.
  1035. =item mdtm ( FILE )
  1036. Returns the I<modification time> of the given file
  1037. =item size ( FILE )
  1038. Returns the size in bytes for the given file as stored on the remote server.
  1039. B<NOTE>: The size reported is the size of the stored file on the remote server.
  1040. If the file is subsequently transfered from the server in ASCII mode
  1041. and the remote server and local machine have different ideas about
  1042. "End Of Line" then the size of file on the local machine after transfer
  1043. may be different.
  1044. =item supported ( CMD )
  1045. Returns TRUE if the remote server supports the given command.
  1046. =item hash ( [FILEHANDLE_GLOB_REF],[ BYTES_PER_HASH_MARK] )
  1047. Called without parameters, or with the first argument false, hash marks
  1048. are suppressed. If the first argument is true but not a reference to a
  1049. file handle glob, then \*STDERR is used. The second argument is the number
  1050. of bytes per hash mark printed, and defaults to 1024. In all cases the
  1051. return value is a reference to an array of two: the filehandle glob reference
  1052. and the bytes per hash mark.
  1053. =back
  1054. The following methods can return different results depending on
  1055. how they are called. If the user explicitly calls either
  1056. of the C<pasv> or C<port> methods then these methods will
  1057. return a I<true> or I<false> value. If the user does not
  1058. call either of these methods then the result will be a
  1059. reference to a C<Net::FTP::dataconn> based object.
  1060. =over 4
  1061. =item nlst ( [ DIR ] )
  1062. Send a C<NLST> command to the server, with an optional parameter.
  1063. =item list ( [ DIR ] )
  1064. Same as C<nlst> but using the C<LIST> command
  1065. =item retr ( FILE )
  1066. Begin the retrieval of a file called C<FILE> from the remote server.
  1067. =item stor ( FILE )
  1068. Tell the server that you wish to store a file. C<FILE> is the
  1069. name of the new file that should be created.
  1070. =item stou ( FILE )
  1071. Same as C<stor> but using the C<STOU> command. The name of the unique
  1072. file which was created on the server will be available via the C<unique_name>
  1073. method after the data connection has been closed.
  1074. =item appe ( FILE )
  1075. Tell the server that we want to append some data to the end of a file
  1076. called C<FILE>. If this file does not exist then create it.
  1077. =back
  1078. If for some reason you want to have complete control over the data connection,
  1079. this includes generating it and calling the C<response> method when required,
  1080. then the user can use these methods to do so.
  1081. However calling these methods only affects the use of the methods above that
  1082. can return a data connection. They have no effect on methods C<get>, C<put>,
  1083. C<put_unique> and those that do not require data connections.
  1084. =over 4
  1085. =item port ( [ PORT ] )
  1086. Send a C<PORT> command to the server. If C<PORT> is specified then it is sent
  1087. to the server. If not the a listen socket is created and the correct information
  1088. sent to the server.
  1089. =item pasv ()
  1090. Tell the server to go into passive mode. Returns the text that represents the
  1091. port on which the server is listening, this text is in a suitable form to
  1092. sent to another ftp server using the C<port> method.
  1093. =back
  1094. The following methods can be used to transfer files between two remote
  1095. servers, providing that these two servers can connect directly to each other.
  1096. =over 4
  1097. =item pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
  1098. This method will do a file transfer between two remote ftp servers. If
  1099. C<DEST_FILE> is omitted then the leaf name of C<SRC_FILE> will be used.
  1100. =item pasv_xfer_unique ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
  1101. Like C<pasv_xfer> but the file is stored on the remote server using
  1102. the STOU command.
  1103. =item pasv_wait ( NON_PASV_SERVER )
  1104. This method can be used to wait for a transfer to complete between a passive
  1105. server and a non-passive server. The method should be called on the passive
  1106. server with the C<Net::FTP> object for the non-passive server passed as an
  1107. argument.
  1108. =item abort ()
  1109. Abort the current data transfer.
  1110. =item quit ()
  1111. Send the QUIT command to the remote FTP server and close the socket connection.
  1112. =back
  1113. =head2 Methods for the adventurous
  1114. C<Net::FTP> inherits from C<Net::Cmd> so methods defined in C<Net::Cmd> may
  1115. be used to send commands to the remote FTP server.
  1116. =over 4
  1117. =item quot (CMD [,ARGS])
  1118. Send a command, that Net::FTP does not directly support, to the remote
  1119. server and wait for a response.
  1120. Returns most significant digit of the response code.
  1121. B<WARNING> This call should only be used on commands that do not require
  1122. data connections. Misuse of this method can hang the connection.
  1123. =back
  1124. =head1 THE dataconn CLASS
  1125. Some of the methods defined in C<Net::FTP> return an object which will
  1126. be derived from this class.The dataconn class itself is derived from
  1127. the C<IO::Socket::INET> class, so any normal IO operations can be performed.
  1128. However the following methods are defined in the dataconn class and IO should
  1129. be performed using these.
  1130. =over 4
  1131. =item read ( BUFFER, SIZE [, TIMEOUT ] )
  1132. Read C<SIZE> bytes of data from the server and place it into C<BUFFER>, also
  1133. performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
  1134. given the the timeout value from the command connection will be used.
  1135. Returns the number of bytes read before any <CRLF> translation.
  1136. =item write ( BUFFER, SIZE [, TIMEOUT ] )
  1137. Write C<SIZE> bytes of data from C<BUFFER> to the server, also
  1138. performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
  1139. given the the timeout value from the command connection will be used.
  1140. Returns the number of bytes written before any <CRLF> translation.
  1141. =item abort ()
  1142. Abort the current data transfer.
  1143. =item close ()
  1144. Close the data connection and get a response from the FTP server. Returns
  1145. I<true> if the connection was closed successfully and the first digit of
  1146. the response from the server was a '2'.
  1147. =back
  1148. =head1 UNIMPLEMENTED
  1149. The following RFC959 commands have not been implemented:
  1150. =over 4
  1151. =item B<ALLO>
  1152. Allocates storage for the file to be transferred.
  1153. =item B<SMNT>
  1154. Mount a different file system structure without changing login or
  1155. accounting information.
  1156. =item B<HELP>
  1157. Ask the server for "helpful information" (that's what the RFC says) on
  1158. the commands it accepts.
  1159. =item B<MODE>
  1160. Specifies transfer mode (stream, block or compressed) for file to be
  1161. transferred.
  1162. =item B<SYST>
  1163. Request remote server system identification.
  1164. =item B<STAT>
  1165. Request remote server status.
  1166. =item B<STRU>
  1167. Specifies file structure for file to be transferred.
  1168. =item B<REIN>
  1169. Reinitialize the connection, flushing all I/O and account information.
  1170. =back
  1171. =head1 REPORTING BUGS
  1172. When reporting bugs/problems please include as much information as possible.
  1173. It may be difficult for me to reproduce the problem as almost every setup
  1174. is different.
  1175. A small script which yields the problem will probably be of help. It would
  1176. also be useful if this script was run with the extra options C<Debug => 1>
  1177. passed to the constructor, and the output sent with the bug report. If you
  1178. cannot include a small script then please include a Debug trace from a
  1179. run of your program which does yield the problem.
  1180. =head1 AUTHOR
  1181. Graham Barr <[email protected]>
  1182. =head1 SEE ALSO
  1183. L<Net::Netrc>
  1184. L<Net::Cmd>
  1185. ftp(1), ftpd(8), RFC 959
  1186. http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
  1187. =head1 CREDITS
  1188. Henry Gabryjelski <[email protected]> - for the suggestion of creating directories
  1189. recursively.
  1190. Nathan Torkington <[email protected]> - for some input on the documentation.
  1191. Roderick Schertler <[email protected]> - for various inputs
  1192. =head1 COPYRIGHT
  1193. Copyright (c) 1995-1998 Graham Barr. All rights reserved.
  1194. This program is free software; you can redistribute it and/or modify it
  1195. under the same terms as Perl itself.
  1196. =cut