releasing/cbrtools/perl/Net/FTP.pm
author marvin shi <marvin.shi@nokia.com>
Wed, 17 Nov 2010 14:05:07 +0800
changeset 691 9eeecb73a5d4
parent 602 3145852acc89
permissions -rw-r--r--
fix ou1cimx1#651819
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Net::FTP.pm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# Copyright (c) 1995-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# This program is free software; you can redistribute it and/or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# modify it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# Documentation (at end) improved 1996 by Nathan Torkington <gnat@frii.com>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
package Net::FTP;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
require 5.001;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
use vars qw(@ISA $VERSION);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
use Carp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
use Socket 1.3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use IO::Socket;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use Time::Local;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
use Net::Cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use Net::Config;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use Fcntl qw(O_WRONLY O_RDONLY O_APPEND O_CREAT O_TRUNC);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
$VERSION = "2.72"; # $Id: //depot/libnet/Net/FTP.pm#80 $
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
@ISA     = qw(Exporter Net::Cmd IO::Socket::INET);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
# Someday I will "use constant", when I am not bothered to much about
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
# compatability with older releases of perl
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
use vars qw($TELNET_IAC $TELNET_IP $TELNET_DM);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
($TELNET_IAC,$TELNET_IP,$TELNET_DM) = (255,244,242);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
# Name is too long for AutoLoad, it clashes with pasv_xfer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
sub pasv_xfer_unique {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
    my($sftp,$sfile,$dftp,$dfile) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
    $sftp->pasv_xfer($sfile,$dftp,$dfile,1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
BEGIN {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
  # make a constant so code is fast'ish
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
  my $is_os390 = $^O eq 'os390';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
  *trEBCDIC = sub () { $is_os390 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
# Having problems with AutoLoader
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
#__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
sub new
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
 my $pkg  = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
 my $peer = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
 my %arg  = @_; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
 my $host = $peer;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
 my $fire = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
 my $fire_type = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
 if(exists($arg{Firewall}) || Net::Config->requires_firewall($peer))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
   $fire = $arg{Firewall}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
	|| $ENV{FTP_FIREWALL}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
	|| $NetConfig{ftp_firewall}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
	|| undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
   if(defined $fire)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
     $peer = $fire;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
     delete $arg{Port};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
	 $fire_type = $arg{FirewallType}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
	 || $ENV{FTP_FIREWALL_TYPE}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
	 || $NetConfig{firewall_type}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
	 || undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
 my $ftp = $pkg->SUPER::new(PeerAddr => $peer, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
			    PeerPort => $arg{Port} || 'ftp(21)',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
			    LocalAddr => $arg{'LocalAddr'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
			    Proto    => 'tcp',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
			    Timeout  => defined $arg{Timeout}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
						? $arg{Timeout}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
						: 120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
			   ) or return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
 ${*$ftp}{'net_ftp_host'}     = $host;		# Remote hostname
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
 ${*$ftp}{'net_ftp_type'}     = 'A';		# ASCII/binary/etc mode
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
 ${*$ftp}{'net_ftp_blksize'}  = abs($arg{'BlockSize'} || 10240);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
 ${*$ftp}{'net_ftp_localaddr'} = $arg{'LocalAddr'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
 ${*$ftp}{'net_ftp_firewall'} = $fire
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
	if(defined $fire);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
 ${*$ftp}{'net_ftp_firewall_type'} = $fire_type
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
	if(defined $fire_type);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
 ${*$ftp}{'net_ftp_passive'} = int
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
	exists $arg{Passive}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
	    ? $arg{Passive}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
	    : exists $ENV{FTP_PASSIVE}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
		? $ENV{FTP_PASSIVE}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
		: defined $fire
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
		    ? $NetConfig{ftp_ext_passive}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
		    : $NetConfig{ftp_int_passive};	# Whew! :-)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
 $ftp->hash(exists $arg{Hash} ? $arg{Hash} : 0, 1024);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
 $ftp->autoflush(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
 $ftp->debug(exists $arg{Debug} ? $arg{Debug} : undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
 unless ($ftp->response() == CMD_OK)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
   $ftp->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
   $@ = $ftp->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
   undef $ftp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
 $ftp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
## User interface methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
sub hash {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
    my $ftp = shift;		# self
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
    my($h,$b) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
    unless($h) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
      delete ${*$ftp}{'net_ftp_hash'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
      return [\*STDERR,0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
    ($h,$b) = (ref($h)? $h : \*STDERR, $b || 1024);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
    select((select($h), $|=1)[0]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
    $b = 512 if $b < 512;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
    ${*$ftp}{'net_ftp_hash'} = [$h, $b];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
}        
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
sub quit
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
 $ftp->_QUIT;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
 $ftp->close;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
sub DESTROY {}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
sub ascii  { shift->type('A',@_); }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
sub binary { shift->type('I',@_); }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
sub ebcdic
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
 carp "TYPE E is unsupported, shall default to I";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
 shift->type('E',@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
sub byte
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
 carp "TYPE L is unsupported, shall default to I";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
 shift->type('L',@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
# Allow the user to send a command directly, BE CAREFUL !!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
sub quot
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
{ 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
 $ftp->command( uc $cmd, @_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
 $ftp->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
sub site
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
 $ftp->command("SITE", @_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
 $ftp->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
sub mdtm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
 my $ftp  = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
 my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
 # Server Y2K defect workaround
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
 #
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
 # sigh; some idiotic FTP servers use ("19%d",tm.tm_year) instead of 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
 # ("%d",tm.tm_year+1900).  This results in an extra digit in the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
 # string returned. To account for this we allow an optional extra
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
 # digit in the year. Then if the first two digits are 19 we use the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
 # remainder, otherwise we subtract 1900 from the whole year.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
 $ftp->_MDTM($file) && $ftp->message =~ /((\d\d)(\d\d\d?))(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
    ? timegm($8,$7,$6,$5,$4-1,$2 eq '19' ? $3 : ($1-1900))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
    : undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
sub size {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
  my $ftp  = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
  my $io;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
  if($ftp->supported("SIZE")) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
    return $ftp->_SIZE($file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
	? ($ftp->message =~ /(\d+)\s*$/)[0]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
	: undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
 elsif($ftp->supported("STAT")) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
   my @msg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
   return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
       unless $ftp->_STAT($file) && (@msg = $ftp->message) == 3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
   my $line;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
   foreach $line (@msg) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
     return (split(/\s+/,$line))[4]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
	 if $line =~ /^[-rwxSsTt]{10}/
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
 else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
   my @files = $ftp->dir($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
   if(@files) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
     return (split(/\s+/,$1))[4]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
	 if $files[0] =~ /^([-rwxSsTt]{10}.*)$/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
 undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
sub login {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
  my($ftp,$user,$pass,$acct) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
  my($ok,$ruser,$fwtype);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
  unless (defined $user) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
    require Net::Netrc;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
    my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
    ($user,$pass,$acct) = $rc->lpa()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
	 if ($rc);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
  $user ||= "anonymous";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
  $ruser = $user;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
  $fwtype = ${*$ftp}{'net_ftp_firewall_type'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
  || $NetConfig{'ftp_firewall_type'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
  || 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
  if ($fwtype && defined ${*$ftp}{'net_ftp_firewall'}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
    if ($fwtype == 1 || $fwtype == 7) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
      $user .= '@' . ${*$ftp}{'net_ftp_host'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
      require Net::Netrc;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
      my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
      my($fwuser,$fwpass,$fwacct) = $rc ? $rc->lpa() : ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
      if ($fwtype == 5) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
	$user = join('@',$user,$fwuser,${*$ftp}{'net_ftp_host'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
	$pass = $pass . '@' . $fwpass;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
      else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
	if ($fwtype == 2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
	  $user .= '@' . ${*$ftp}{'net_ftp_host'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
	elsif ($fwtype == 6) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
	  $fwuser .= '@' . ${*$ftp}{'net_ftp_host'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
	$ok = $ftp->_USER($fwuser);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
	return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
	$ok = $ftp->_PASS($fwpass || "");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
	return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
	$ok = $ftp->_ACCT($fwacct)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
	  if defined($fwacct);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
	if ($fwtype == 3) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
          $ok = $ftp->command("SITE",${*$ftp}{'net_ftp_host'})->response;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
	elsif ($fwtype == 4) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
          $ok = $ftp->command("OPEN",${*$ftp}{'net_ftp_host'})->response;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
	return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
  $ok = $ftp->_USER($user);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
  # Some dumb firewalls don't prefix the connection messages
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
  $ok = $ftp->response()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
	 if ($ok == CMD_OK && $ftp->code == 220 && $user =~ /\@/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
  if ($ok == CMD_MORE) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
    unless(defined $pass) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
      require Net::Netrc;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
      my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'}, $ruser);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
      ($ruser,$pass,$acct) = $rc->lpa()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
	 if ($rc);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
      $pass = '-anonymous@'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
         if (!defined $pass && (!defined($ruser) || $ruser =~ /^anonymous/o));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
    $ok = $ftp->_PASS($pass || "");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
  $ok = $ftp->_ACCT($acct)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
	 if (defined($acct) && ($ok == CMD_MORE || $ok == CMD_OK));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
  if ($fwtype == 7 && $ok == CMD_OK && defined ${*$ftp}{'net_ftp_firewall'}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
    my($f,$auth,$resp) = _auth_id($ftp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
    $ftp->authorize($auth,$resp) if defined($resp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
  $ok == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
sub account
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
 @_ == 2 or croak 'usage: $ftp->account( ACCT )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
 my $acct = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
 $ftp->_ACCT($acct) == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
sub _auth_id {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
 my($ftp,$auth,$resp) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
 unless(defined $resp)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
   require Net::Netrc;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
   $auth ||= eval { (getpwuid($>))[0] } || $ENV{NAME};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
   my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'}, $auth)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
        || Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
   ($auth,$resp) = $rc->lpa()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
     if ($rc);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
  ($ftp,$auth,$resp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
sub authorize
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
 @_ >= 1 || @_ <= 3 or croak 'usage: $ftp->authorize( [AUTH [, RESP]])';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
 my($ftp,$auth,$resp) = &_auth_id;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
 my $ok = $ftp->_AUTH($auth || "");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
 $ok = $ftp->_RESP($resp || "")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
	if ($ok == CMD_MORE);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
 $ok == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
sub rename
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
 @_ == 3 or croak 'usage: $ftp->rename(FROM, TO)';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
 my($ftp,$from,$to) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
 $ftp->_RNFR($from)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
    && $ftp->_RNTO($to);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
sub type
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
 my $type = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
 my $oldval = ${*$ftp}{'net_ftp_type'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
 return $oldval
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
	unless (defined $type);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
 return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
	unless ($ftp->_TYPE($type,@_));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
 ${*$ftp}{'net_ftp_type'} = join(" ",$type,@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
 $oldval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
sub alloc
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
 my $size = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
 my $oldval = ${*$ftp}{'net_ftp_allo'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
 return $oldval
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
	unless (defined $size);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
 return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
	unless ($ftp->_ALLO($size,@_));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
 ${*$ftp}{'net_ftp_allo'} = join(" ",$size,@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
 $oldval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
sub abort
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
 send($ftp,pack("CCC", $TELNET_IAC, $TELNET_IP, $TELNET_IAC),MSG_OOB);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
 $ftp->command(pack("C",$TELNET_DM) . "ABOR");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
 ${*$ftp}{'net_ftp_dataconn'}->close()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
    if defined ${*$ftp}{'net_ftp_dataconn'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
 $ftp->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
 $ftp->status == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
sub get
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
 my($ftp,$remote,$local,$where) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
 my($loc,$len,$buf,$resp,$data);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
 local *FD;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
 my $localfd = ref($local) || ref(\$local) eq "GLOB";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
 ($local = $remote) =~ s#^.*/##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
	unless(defined $local);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
 croak("Bad remote filename '$remote'\n")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
	if $remote =~ /[\r\n]/s;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
 ${*$ftp}{'net_ftp_rest'} = $where
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
	if ($where);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
 delete ${*$ftp}{'net_ftp_port'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
 delete ${*$ftp}{'net_ftp_pasv'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
 $data = $ftp->retr($remote) or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
 if($localfd)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
   $loc = $local;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
 else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
   $loc = \*FD;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
   unless(sysopen($loc, $local, O_CREAT | O_WRONLY | ($where ? O_APPEND : O_TRUNC)))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
     carp "Cannot open Local file $local: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
     $data->abort;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
 if($ftp->type eq 'I' && !binmode($loc))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
   carp "Cannot binmode Local file $local: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
   $data->abort;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
   close($loc) unless $localfd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
   return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
 $buf = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
 my($count,$hashh,$hashb,$ref) = (0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
 ($hashh,$hashb) = @$ref
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
   if($ref = ${*$ftp}{'net_ftp_hash'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
 my $blksize = ${*$ftp}{'net_ftp_blksize'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
 local $\; # Just in case
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
 while(1)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
   last unless $len = $data->read($buf,$blksize);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
   if (trEBCDIC && $ftp->type ne 'I')
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
     $buf = $ftp->toebcdic($buf);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
     $len = length($buf);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
   if($hashh) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
    $count += $len;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
    print $hashh "#" x (int($count / $hashb));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
    $count %= $hashb;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
   unless(print $loc $buf)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
     carp "Cannot write to Local file $local: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
     $data->abort;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
     close($loc)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
        unless $localfd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
 print $hashh "\n" if $hashh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
 unless ($localfd)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
   unless (close($loc))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
     carp "Cannot close file $local (perhaps disk space) $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
 unless ($data->close()) # implied $ftp->response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
   carp "Unable to close datastream";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
   return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
 return $local;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
sub cwd
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
 @_ == 1 || @_ == 2 or croak 'usage: $ftp->cwd( [ DIR ] )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
 my($ftp,$dir) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
 $dir = "/" unless defined($dir) && $dir =~ /\S/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
 $dir eq ".."
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
    ? $ftp->_CDUP()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   542
    : $ftp->_CWD($dir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
sub cdup
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
 @_ == 1 or croak 'usage: $ftp->cdup()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
 $_[0]->_CDUP;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
sub pwd
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
 @_ == 1 || croak 'usage: $ftp->pwd()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
 $ftp->_PWD();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
 $ftp->_extract_path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
# rmdir( $ftp, $dir, [ $recurse ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
# Removes $dir on remote host via FTP.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
# $ftp is handle for remote host
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
# If $recurse is TRUE, the directory and deleted recursively.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
# This means all of its contents and subdirectories.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
# Initial version contributed by Dinkum Software
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
sub rmdir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
    @_ == 2 || @_ == 3 or croak('usage: $ftp->rmdir( DIR [, RECURSE ] )');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
    # Pick off the args
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
    my ($ftp, $dir, $recurse) = @_ ;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
    my $ok;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
    return $ok
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
	if $ok = $ftp->_RMD( $dir ) or !$recurse;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
    # Try to delete the contents
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
    # Get a list of all the files in the directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
    my $filelist = $ftp->ls($dir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
    return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
	unless $filelist && @$filelist; # failed, it is probably not a directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
    # Go thru and delete each file or the directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
    my $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
    foreach $file (map { m,/, ? $_ : "$dir/$_" } @$filelist)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
	next  # successfully deleted the file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
	    if $ftp->delete($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
	# Failed to delete it, assume its a directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
	# Recurse and ignore errors, the final rmdir() will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
	# fail on any errors here
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
	return $ok
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
	    unless $ok = $ftp->rmdir($file, 1) ;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
    # Directory should be empty
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
    # Try to remove the directory again
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
    # Pass results directly to caller
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
    # If any of the prior deletes failed, this
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
    # rmdir() will fail because directory is not empty
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
    return $ftp->_RMD($dir) ;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
sub restart
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
  @_ == 2 || croak 'usage: $ftp->restart( BYTE_OFFSET )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
  my($ftp,$where) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
  ${*$ftp}{'net_ftp_rest'} = $where;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
  return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
sub mkdir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
 @_ == 2 || @_ == 3 or croak 'usage: $ftp->mkdir( DIR [, RECURSE ] )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
 my($ftp,$dir,$recurse) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
 $ftp->_MKD($dir) || $recurse or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
    return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
 my $path = $dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
 unless($ftp->ok)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
   my @path = split(m#(?=/+)#, $dir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
   $path = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
   while(@path)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
     $path .= shift @path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
     $ftp->_MKD($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
     $path = $ftp->_extract_path($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
   # If the creation of the last element was not successful, see if we
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
   # can cd to it, if so then return path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
   unless($ftp->ok)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
     my($status,$message) = ($ftp->status,$ftp->message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
     my $pwd = $ftp->pwd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
     if($pwd && $ftp->cwd($dir))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
       $path = $dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
       $ftp->cwd($pwd);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
     else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
       undef $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
     $ftp->set_status($status,$message);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
 $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
sub delete
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
 @_ == 2 || croak 'usage: $ftp->delete( FILENAME )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
 $_[0]->_DELE($_[1]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
sub put        { shift->_store_cmd("stor",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
sub put_unique { shift->_store_cmd("stou",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
sub append     { shift->_store_cmd("appe",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
sub nlst { shift->_data_cmd("NLST",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
sub list { shift->_data_cmd("LIST",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
sub retr { shift->_data_cmd("RETR",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
sub stor { shift->_data_cmd("STOR",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
sub stou { shift->_data_cmd("STOU",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
sub appe { shift->_data_cmd("APPE",@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
sub _store_cmd 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
 my($ftp,$cmd,$local,$remote) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
 my($loc,$sock,$len,$buf);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
 local *FD;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
 my $localfd = ref($local) || ref(\$local) eq "GLOB";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
 unless(defined $remote)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
   croak 'Must specify remote filename with stream input'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
	if $localfd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
   require File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
   $remote = File::Basename::basename($local);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
 if( defined ${*$ftp}{'net_ftp_allo'} ) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
   delete ${*$ftp}{'net_ftp_allo'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
  } else 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
   # if the user hasn't already invoked the alloc method since the last 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
   # _store_cmd call, figure out if the local file is a regular file(not
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
   # a pipe, or device) and if so get the file size from stat, and send
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
   # an ALLO command before sending the STOR, STOU, or APPE command.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
   my $size = -f $local && -s _; # no ALLO if sending data from a pipe
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
   $ftp->_ALLO($size) if $size;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
 croak("Bad remote filename '$remote'\n")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
	if $remote =~ /[\r\n]/s;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
 if($localfd)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
   $loc = $local;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
 else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
   $loc = \*FD;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
   unless(sysopen($loc, $local, O_RDONLY))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
     carp "Cannot open Local file $local: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
 if($ftp->type eq 'I' && !binmode($loc))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
   carp "Cannot binmode Local file $local: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
   return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
 delete ${*$ftp}{'net_ftp_port'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
 delete ${*$ftp}{'net_ftp_pasv'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
 $sock = $ftp->_data_cmd($cmd, $remote) or 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
 $remote = ($ftp->message =~ /FILE:\s*(.*)/)[0]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
   if 'STOU' eq uc $cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
 my $blksize = ${*$ftp}{'net_ftp_blksize'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
 my($count,$hashh,$hashb,$ref) = (0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
 ($hashh,$hashb) = @$ref
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
   if($ref = ${*$ftp}{'net_ftp_hash'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
 while(1)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
   last unless $len = read($loc,$buf="",$blksize);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
   if (trEBCDIC && $ftp->type ne 'I')
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   764
     $buf = $ftp->toascii($buf); 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   765
     $len = length($buf);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   766
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   767
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   768
   if($hashh) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   769
    $count += $len;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   770
    print $hashh "#" x (int($count / $hashb));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   771
    $count %= $hashb;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   772
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   773
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   774
   my $wlen;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   775
   unless(defined($wlen = $sock->write($buf,$len)) && $wlen == $len)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   776
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   777
     $sock->abort;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   778
     close($loc)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   779
	unless $localfd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   780
     print $hashh "\n" if $hashh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   781
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   782
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   783
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   784
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   785
 print $hashh "\n" if $hashh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   786
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   787
 close($loc)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   788
	unless $localfd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   789
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   790
 $sock->close() or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   791
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   792
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   793
 if ('STOU' eq uc $cmd and $ftp->message =~ m/unique\s+file\s*name\s*:\s*(.*)\)|"(.*)"/)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   794
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   795
   require File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   796
   $remote = File::Basename::basename($+) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   797
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   798
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   799
 return $remote;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   800
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   801
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   802
sub port
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   803
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   804
 @_ == 1 || @_ == 2 or croak 'usage: $ftp->port([PORT])';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   805
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   806
 my($ftp,$port) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   807
 my $ok;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   808
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   809
 delete ${*$ftp}{'net_ftp_intern_port'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   810
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   811
 unless(defined $port)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   812
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   813
   # create a Listen socket at same address as the command socket
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   814
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   815
   ${*$ftp}{'net_ftp_listen'} ||= IO::Socket::INET->new(Listen    => 5,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   816
				    	    	        Proto     => 'tcp',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   817
							Timeout   => $ftp->timeout,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   818
							LocalAddr => $ftp->sockhost,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   819
				    	    	       );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   820
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   821
   my $listen = ${*$ftp}{'net_ftp_listen'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   822
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   823
   my($myport, @myaddr) = ($listen->sockport, split(/\./,$listen->sockhost));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   824
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   825
   $port = join(',', @myaddr, $myport >> 8, $myport & 0xff);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   826
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   827
   ${*$ftp}{'net_ftp_intern_port'} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   828
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   829
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   830
 $ok = $ftp->_PORT($port);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   831
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   832
 ${*$ftp}{'net_ftp_port'} = $port;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   833
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   834
 $ok;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   835
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   836
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   837
sub ls  { shift->_list_cmd("NLST",@_); }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   838
sub dir { shift->_list_cmd("LIST",@_); }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   839
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   840
sub pasv
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   841
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   842
 @_ == 1 or croak 'usage: $ftp->pasv()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   843
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   844
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   845
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   846
 delete ${*$ftp}{'net_ftp_intern_port'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   847
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   848
 $ftp->_PASV && $ftp->message =~ /(\d+(,\d+)+)/
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   849
    ? ${*$ftp}{'net_ftp_pasv'} = $1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   850
    : undef;    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   851
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   852
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   853
sub unique_name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   854
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   855
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   856
 ${*$ftp}{'net_ftp_unique'} || undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   857
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   858
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   859
sub supported {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   860
    @_ == 2 or croak 'usage: $ftp->supported( CMD )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   861
    my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   862
    my $cmd = uc shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   863
    my $hash = ${*$ftp}{'net_ftp_supported'} ||= {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   864
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   865
    return $hash->{$cmd}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   866
        if exists $hash->{$cmd};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   867
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   868
    return $hash->{$cmd} = 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   869
	unless $ftp->_HELP($cmd);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   870
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   871
    my $text = $ftp->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   872
    if($text =~ /following\s+commands/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   873
	$text =~ s/^.*\n//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   874
        while($text =~ /(\*?)(\w+)(\*?)/sg) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   875
            $hash->{"\U$2"} = !length("$1$3");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   876
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   877
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   878
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   879
	$hash->{$cmd} = $text !~ /unimplemented/i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   880
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   881
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   882
    $hash->{$cmd} ||= 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   883
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   884
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   885
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   886
## Deprecated methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   887
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   888
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   889
sub lsl
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   890
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   891
 carp "Use of Net::FTP::lsl deprecated, use 'dir'"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   892
    if $^W;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   893
 goto &dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   894
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   895
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   896
sub authorise
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   897
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   898
 carp "Use of Net::FTP::authorise deprecated, use 'authorize'"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   899
    if $^W;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   900
 goto &authorize;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   901
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   902
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   903
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   904
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   905
## Private methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   906
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   907
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   908
sub _extract_path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   909
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   910
 my($ftp, $path) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   911
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   912
 # This tries to work both with and without the quote doubling
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   913
 # convention (RFC 959 requires it, but the first 3 servers I checked
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   914
 # didn't implement it).  It will fail on a server which uses a quote in
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   915
 # the message which isn't a part of or surrounding the path.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   916
 $ftp->ok &&
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   917
    $ftp->message =~ /(?:^|\s)\"(.*)\"(?:$|\s)/ &&
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   918
    ($path = $1) =~ s/\"\"/\"/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   919
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   920
 $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   921
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   922
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   923
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   924
## Communication methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   925
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   926
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   927
sub _dataconn
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   928
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   929
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   930
 my $data = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   931
 my $pkg = "Net::FTP::" . $ftp->type;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   932
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   933
 eval "require " . $pkg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   934
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   935
 $pkg =~ s/ /_/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   936
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   937
 delete ${*$ftp}{'net_ftp_dataconn'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   938
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   939
 if(defined ${*$ftp}{'net_ftp_pasv'})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   940
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   941
   my @port = split(/,/,${*$ftp}{'net_ftp_pasv'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   942
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   943
   $data = $pkg->new(PeerAddr => join(".",@port[0..3]),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   944
    	    	     PeerPort => $port[4] * 256 + $port[5],
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   945
		     LocalAddr => ${*$ftp}{'net_ftp_localaddr'},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   946
    	    	     Proto    => 'tcp'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   947
    	    	    );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   948
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   949
 elsif(defined ${*$ftp}{'net_ftp_listen'})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   950
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   951
   $data = ${*$ftp}{'net_ftp_listen'}->accept($pkg);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   952
   close(delete ${*$ftp}{'net_ftp_listen'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   953
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   954
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   955
 if($data)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   956
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   957
   ${*$data} = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   958
   $data->timeout($ftp->timeout);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   959
   ${*$ftp}{'net_ftp_dataconn'} = $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   960
   ${*$data}{'net_ftp_cmd'} = $ftp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   961
   ${*$data}{'net_ftp_blksize'} = ${*$ftp}{'net_ftp_blksize'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   962
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   963
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   964
 $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   965
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   966
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   967
sub _list_cmd
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   968
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   969
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   970
 my $cmd = uc shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   971
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   972
 delete ${*$ftp}{'net_ftp_port'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   973
 delete ${*$ftp}{'net_ftp_pasv'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   974
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   975
 my $data = $ftp->_data_cmd($cmd,@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   976
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   977
 return
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   978
	unless(defined $data);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   979
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   980
 require Net::FTP::A;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   981
 bless $data, "Net::FTP::A"; # Force ASCII mode
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   982
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   983
 my $databuf = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   984
 my $buf = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   985
 my $blksize = ${*$ftp}{'net_ftp_blksize'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   986
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   987
 while($data->read($databuf,$blksize)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   988
   $buf .= $databuf;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   989
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   990
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   991
 my $list = [ split(/\n/,$buf) ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   992
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   993
 $data->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   994
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   995
 if (trEBCDIC)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   996
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   997
   for (@$list) { $_ = $ftp->toebcdic($_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   998
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   999
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1000
 wantarray ? @{$list}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1001
           : $list;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1002
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1003
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1004
sub _data_cmd
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1005
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1006
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1007
 my $cmd = uc shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1008
 my $ok = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1009
 my $where = delete ${*$ftp}{'net_ftp_rest'} || 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1010
 my $arg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1011
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1012
 for $arg (@_) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1013
   croak("Bad argument '$arg'\n")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1014
	if $arg =~ /[\r\n]/s;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1015
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1016
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1017
 if(${*$ftp}{'net_ftp_passive'} &&
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1018
     !defined ${*$ftp}{'net_ftp_pasv'} &&
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1019
     !defined ${*$ftp}{'net_ftp_port'})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1020
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1021
   my $data = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1022
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1023
   $ok = defined $ftp->pasv;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1024
   $ok = $ftp->_REST($where)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1025
	if $ok && $where;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1026
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1027
   if($ok)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1028
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1029
     $ftp->command($cmd,@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1030
     $data = $ftp->_dataconn();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1031
     $ok = CMD_INFO == $ftp->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1032
     if($ok) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1033
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1034
       $data->reading
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1035
         if $data && $cmd =~ /RETR|LIST|NLST/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1036
       return $data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1037
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1038
     $data->_close
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1039
	if $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1040
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1041
   return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1042
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1043
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1044
 $ok = $ftp->port
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1045
    unless (defined ${*$ftp}{'net_ftp_port'} ||
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1046
            defined ${*$ftp}{'net_ftp_pasv'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1047
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1048
 $ok = $ftp->_REST($where)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1049
    if $ok && $where;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1050
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1051
 return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1052
    unless $ok;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1053
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1054
 $ftp->command($cmd,@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1055
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1056
 return 1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1057
    if(defined ${*$ftp}{'net_ftp_pasv'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1058
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1059
 $ok = CMD_INFO == $ftp->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1060
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1061
 return $ok 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1062
    unless exists ${*$ftp}{'net_ftp_intern_port'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1063
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1064
 if($ok) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1065
   my $data = $ftp->_dataconn();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1066
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1067
   $data->reading
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1068
         if $data && $cmd =~ /RETR|LIST|NLST/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1069
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1070
   return $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1071
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1072
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1073
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1074
 close(delete ${*$ftp}{'net_ftp_listen'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1075
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1076
 return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1077
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1078
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1079
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1080
## Over-ride methods (Net::Cmd)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1081
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1082
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1083
sub debug_text { $_[2] =~ /^(pass|resp|acct)/i ? "$1 ....\n" : $_[2]; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1084
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1085
sub command
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1086
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1087
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1088
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1089
 delete ${*$ftp}{'net_ftp_port'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1090
 $ftp->SUPER::command(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1091
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1092
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1093
sub response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1094
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1095
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1096
 my $code = $ftp->SUPER::response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1097
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1098
 delete ${*$ftp}{'net_ftp_pasv'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1099
    if ($code != CMD_MORE && $code != CMD_INFO);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1100
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1101
 $code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1102
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1103
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1104
sub parse_response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1105
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1106
 return ($1, $2 eq "-")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1107
    if $_[1] =~ s/^(\d\d\d)(.?)//o;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1108
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1109
 my $ftp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1110
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1111
 return ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1112
	unless ${*$ftp}{'net_cmd_code'} + 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1113
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1114
 (${*$ftp}{'net_cmd_code'},1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1115
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1116
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1117
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1118
## Allow 2 servers to talk directly
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1119
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1121
sub pasv_xfer {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1122
    my($sftp,$sfile,$dftp,$dfile,$unique) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1123
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1124
    ($dfile = $sfile) =~ s#.*/##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1125
	unless(defined $dfile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1126
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1127
    my $port = $sftp->pasv or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1128
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1129
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1130
    $dftp->port($port) or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1131
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1132
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1133
    return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1134
	unless($unique ? $dftp->stou($dfile) : $dftp->stor($dfile));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1135
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1136
    unless($sftp->retr($sfile) && $sftp->response == CMD_INFO) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1137
	$sftp->retr($sfile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1138
	$dftp->abort;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1139
	$dftp->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1140
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1141
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1142
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1143
    $dftp->pasv_wait($sftp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1144
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1145
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1146
sub pasv_wait
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1147
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1148
 @_ == 2 or croak 'usage: $ftp->pasv_wait(NON_PASV_FTP)';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1149
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1150
 my($ftp, $non_pasv) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1151
 my($file,$rin,$rout);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1152
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1153
 vec($rin='',fileno($ftp),1) = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1154
 select($rout=$rin, undef, undef, undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1156
 $ftp->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1157
 $non_pasv->response();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1158
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1159
 return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1160
	unless $ftp->ok() && $non_pasv->ok();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1162
 return $1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1163
	if $ftp->message =~ /unique file name:\s*(\S*)\s*\)/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1164
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1165
 return $1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1166
	if $non_pasv->message =~ /unique file name:\s*(\S*)\s*\)/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1167
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1168
 return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1169
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1170
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1171
sub cmd { shift->command(@_)->response() }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1172
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1173
########################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1174
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1175
# RFC959 commands
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1176
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1177
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1178
sub _ABOR { shift->command("ABOR")->response()	 == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1179
sub _ALLO { shift->command("ALLO",@_)->response() == CMD_OK}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1180
sub _CDUP { shift->command("CDUP")->response()	 == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1181
sub _NOOP { shift->command("NOOP")->response()	 == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1182
sub _PASV { shift->command("PASV")->response()	 == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1183
sub _QUIT { shift->command("QUIT")->response()	 == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1184
sub _DELE { shift->command("DELE",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1185
sub _CWD  { shift->command("CWD", @_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1186
sub _PORT { shift->command("PORT",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1187
sub _RMD  { shift->command("RMD", @_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1188
sub _MKD  { shift->command("MKD", @_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1189
sub _PWD  { shift->command("PWD", @_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1190
sub _TYPE { shift->command("TYPE",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1191
sub _RNTO { shift->command("RNTO",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1192
sub _RESP { shift->command("RESP",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1193
sub _MDTM { shift->command("MDTM",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1194
sub _SIZE { shift->command("SIZE",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1195
sub _HELP { shift->command("HELP",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1196
sub _STAT { shift->command("STAT",@_)->response() == CMD_OK }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1197
sub _APPE { shift->command("APPE",@_)->response() == CMD_INFO }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1198
sub _LIST { shift->command("LIST",@_)->response() == CMD_INFO }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1199
sub _NLST { shift->command("NLST",@_)->response() == CMD_INFO }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1200
sub _RETR { shift->command("RETR",@_)->response() == CMD_INFO }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1201
sub _STOR { shift->command("STOR",@_)->response() == CMD_INFO }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1202
sub _STOU { shift->command("STOU",@_)->response() == CMD_INFO }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1203
sub _RNFR { shift->command("RNFR",@_)->response() == CMD_MORE }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1204
sub _REST { shift->command("REST",@_)->response() == CMD_MORE }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1205
sub _USER { shift->command("user",@_)->response() } # A certain brain dead firewall :-)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1206
sub _PASS { shift->command("PASS",@_)->response() }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1207
sub _ACCT { shift->command("ACCT",@_)->response() }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1208
sub _AUTH { shift->command("AUTH",@_)->response() }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1209
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1210
sub _SMNT { shift->unsupported(@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1211
sub _MODE { shift->unsupported(@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1212
sub _SYST { shift->unsupported(@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1213
sub _STRU { shift->unsupported(@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1214
sub _REIN { shift->unsupported(@_) }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1215
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1216
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1217
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1218
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1219
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1220
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1221
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1222
Net::FTP - FTP Client class
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1223
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1224
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1225
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1226
    use Net::FTP;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1227
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1228
    $ftp = Net::FTP->new("some.host.name", Debug => 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1229
      or die "Cannot connect to some.host.name: $@";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1230
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1231
    $ftp->login("anonymous",'-anonymous@')
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1232
      or die "Cannot login ", $ftp->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1234
    $ftp->cwd("/pub")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1235
      or die "Cannot change working directory ", $ftp->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1236
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1237
    $ftp->get("that.file")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1238
      or die "get failed ", $ftp->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1239
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1240
    $ftp->quit;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1241
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1242
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1243
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1244
C<Net::FTP> is a class implementing a simple FTP client in Perl as
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1245
described in RFC959.  It provides wrappers for a subset of the RFC959
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1246
commands.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1247
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1248
=head1 OVERVIEW
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1249
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1250
FTP stands for File Transfer Protocol.  It is a way of transferring
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1251
files between networked machines.  The protocol defines a client
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1252
(whose commands are provided by this module) and a server (not
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1253
implemented in this module).  Communication is always initiated by the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1254
client, and the server responds with a message and a status code (and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1255
sometimes with data).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1256
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1257
The FTP protocol allows files to be sent to or fetched from the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1258
server.  Each transfer involves a B<local file> (on the client) and a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1259
B<remote file> (on the server).  In this module, the same file name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1260
will be used for both local and remote if only one is specified.  This
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1261
means that transferring remote file C</path/to/file> will try to put
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1262
that file in C</path/to/file> locally, unless you specify a local file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1263
name.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1264
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1265
The protocol also defines several standard B<translations> which the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1266
file can undergo during transfer.  These are ASCII, EBCDIC, binary,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1267
and byte.  ASCII is the default type, and indicates that the sender of
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1268
files will translate the ends of lines to a standard representation
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1269
which the receiver will then translate back into their local
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1270
representation.  EBCDIC indicates the file being transferred is in
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1271
EBCDIC format.  Binary (also known as image) format sends the data as
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1272
a contiguous bit stream.  Byte format transfers the data as bytes, the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1273
values of which remain the same regardless of differences in byte size
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1274
between the two machines (in theory - in practice you should only use
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1275
this if you really know what you're doing).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1276
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1277
=head1 CONSTRUCTOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1278
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1279
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1280
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1281
=item new (HOST [,OPTIONS])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1282
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1283
This is the constructor for a new Net::FTP object. C<HOST> is the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1284
name of the remote host to which an FTP connection is required.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1285
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1286
C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1287
Possible options are:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1288
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1289
B<Firewall> - The name of a machine which acts as an FTP firewall. This can be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1290
overridden by an environment variable C<FTP_FIREWALL>. If specified, and the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1291
given host cannot be directly connected to, then the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1292
connection is made to the firewall machine and the string C<@hostname> is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1293
appended to the login identifier. This kind of setup is also refered to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1294
as an ftp proxy.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1295
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1296
B<FirewallType> - The type of firewall running on the machine indicated by
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1297
B<Firewall>. This can be overridden by an environment variable
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1298
C<FTP_FIREWALL_TYPE>. For a list of permissible types, see the description of
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1299
ftp_firewall_type in L<Net::Config>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1301
B<BlockSize> - This is the block size that Net::FTP will use when doing
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1302
transfers. (defaults to 10240)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1303
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1304
B<Port> - The port number to connect to on the remote machine for the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1305
FTP connection
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1306
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1307
B<Timeout> - Set a timeout value (defaults to 120)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1308
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1309
B<Debug> - debug level (see the debug method in L<Net::Cmd>)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1310
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1311
B<Passive> - If set to a non-zero value then all data transfers will be done
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1312
using passive mode. This is not usually required except for some I<dumb>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1313
servers, and some firewall configurations. This can also be set by the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1314
environment variable C<FTP_PASSIVE>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1315
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1316
B<Hash> - If given a reference to a file handle (e.g., C<\*STDERR>),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1317
print hash marks (#) on that filehandle every 1024 bytes.  This
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1318
simply invokes the C<hash()> method for you, so that hash marks
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1319
are displayed for all transfers.  You can, of course, call C<hash()>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1320
explicitly whenever you'd like.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1321
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1322
B<LocalAddr> - Local address to use for all socket connections, this
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1323
argument will be passed to L<IO::Socket::INET>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1324
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1325
If the constructor fails undef will be returned and an error message will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1326
be in $@
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1327
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1328
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1329
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1330
=head1 METHODS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1331
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1332
Unless otherwise stated all methods return either a I<true> or I<false>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1333
value, with I<true> meaning that the operation was a success. When a method
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1334
states that it returns a value, failure will be returned as I<undef> or an
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1335
empty list.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1336
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1337
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1339
=item login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1340
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1341
Log into the remote FTP server with the given login information. If
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1342
no arguments are given then the C<Net::FTP> uses the C<Net::Netrc>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1343
package to lookup the login information for the connected host.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1344
If no information is found then a login of I<anonymous> is used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1345
If no password is given and the login is I<anonymous> then I<anonymous@>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1346
will be used for password.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1347
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1348
If the connection is via a firewall then the C<authorize> method will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1349
be called with no arguments.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1350
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1351
=item authorize ( [AUTH [, RESP]])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1352
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1353
This is a protocol used by some firewall ftp proxies. It is used
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1354
to authorise the user to send data out.  If both arguments are not specified
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1355
then C<authorize> uses C<Net::Netrc> to do a lookup.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1356
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1357
=item site (ARGS)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1358
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1359
Send a SITE command to the remote server and wait for a response.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1360
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1361
Returns most significant digit of the response code.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1362
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1363
=item ascii
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1364
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1365
Transfer file in ASCII. CRLF translation will be done if required
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1366
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1367
=item binary
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1368
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1369
Transfer file in binary mode. No transformation will be done.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1370
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1371
B<Hint>: If both server and client machines use the same line ending for
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1372
text files, then it will be faster to transfer all files in binary mode.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1373
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1374
=item rename ( OLDNAME, NEWNAME )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1375
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1376
Rename a file on the remote FTP server from C<OLDNAME> to C<NEWNAME>. This
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1377
is done by sending the RNFR and RNTO commands.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1378
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1379
=item delete ( FILENAME )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1380
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1381
Send a request to the server to delete C<FILENAME>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1382
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1383
=item cwd ( [ DIR ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1384
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1385
Attempt to change directory to the directory given in C<$dir>.  If
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1386
C<$dir> is C<"..">, the FTP C<CDUP> command is used to attempt to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1387
move up one directory. If no directory is given then an attempt is made
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1388
to change the directory to the root directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1389
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1390
=item cdup ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1391
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1392
Change directory to the parent of the current directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1393
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1394
=item pwd ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1395
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1396
Returns the full pathname of the current directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1397
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1398
=item restart ( WHERE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1399
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1400
Set the byte offset at which to begin the next data transfer. Net::FTP simply
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1401
records this value and uses it when during the next data transfer. For this
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1402
reason this method will not return an error, but setting it may cause
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1403
a subsequent data transfer to fail.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1404
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1405
=item rmdir ( DIR [, RECURSE ])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1406
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1407
Remove the directory with the name C<DIR>. If C<RECURSE> is I<true> then
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1408
C<rmdir> will attempt to delete everything inside the directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1409
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1410
=item mkdir ( DIR [, RECURSE ])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1411
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1412
Create a new directory with the name C<DIR>. If C<RECURSE> is I<true> then
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1413
C<mkdir> will attempt to create all the directories in the given path.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1414
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1415
Returns the full pathname to the new directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1416
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1417
=item ls ( [ DIR ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1418
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1419
=item alloc ( SIZE [, RECORD_SIZE] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1420
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1421
The alloc command allows you to give the ftp server a hint about the size
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1422
of the file about to be transfered using the ALLO ftp command. Some storage
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1423
systems use this to make intelligent decisions about how to store the file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1424
The C<SIZE> argument represents the size of the file in bytes. The
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1425
C<RECORD_SIZE> argument indicates a mazimum record or page size for files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1426
sent with a record or page structure.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1427
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1428
The size of the file will be determined, and sent to the server
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1429
automatically for normal files so that this method need only be called if
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1430
you are transfering data from a socket, named pipe, or other stream not
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1431
associated with a normal file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1432
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1433
Get a directory listing of C<DIR>, or the current directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1434
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1435
In an array context, returns a list of lines returned from the server. In
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1436
a scalar context, returns a reference to a list.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1437
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1438
=item dir ( [ DIR ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1439
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1440
Get a directory listing of C<DIR>, or the current directory in long format.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1441
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1442
In an array context, returns a list of lines returned from the server. In
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1443
a scalar context, returns a reference to a list.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1444
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1445
=item get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1446
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1447
Get C<REMOTE_FILE> from the server and store locally. C<LOCAL_FILE> may be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1448
a filename or a filehandle. If not specified, the file will be stored in
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1449
the current directory with the same leafname as the remote file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1450
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1451
If C<WHERE> is given then the first C<WHERE> bytes of the file will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1452
not be transfered, and the remaining bytes will be appended to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1453
the local file if it already exists.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1454
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1455
Returns C<LOCAL_FILE>, or the generated local file name if C<LOCAL_FILE>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1456
is not given. If an error was encountered undef is returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1457
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1458
=item put ( LOCAL_FILE [, REMOTE_FILE ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1459
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1460
Put a file on the remote server. C<LOCAL_FILE> may be a name or a filehandle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1461
If C<LOCAL_FILE> is a filehandle then C<REMOTE_FILE> must be specified. If
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1462
C<REMOTE_FILE> is not specified then the file will be stored in the current
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1463
directory with the same leafname as C<LOCAL_FILE>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1464
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1465
Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1466
is not given.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1467
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1468
B<NOTE>: If for some reason the transfer does not complete and an error is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1469
returned then the contents that had been transfered will not be remove
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1470
automatically.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1471
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1472
=item put_unique ( LOCAL_FILE [, REMOTE_FILE ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1473
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1474
Same as put but uses the C<STOU> command.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1475
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1476
Returns the name of the file on the server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1477
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1478
=item append ( LOCAL_FILE [, REMOTE_FILE ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1479
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1480
Same as put but appends to the file on the remote server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1481
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1482
Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1483
is not given.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1484
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1485
=item unique_name ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1486
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1487
Returns the name of the last file stored on the server using the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1488
C<STOU> command.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1489
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1490
=item mdtm ( FILE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1491
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1492
Returns the I<modification time> of the given file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1493
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1494
=item size ( FILE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1495
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1496
Returns the size in bytes for the given file as stored on the remote server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1497
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1498
B<NOTE>: The size reported is the size of the stored file on the remote server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1499
If the file is subsequently transfered from the server in ASCII mode
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1500
and the remote server and local machine have different ideas about
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1501
"End Of Line" then the size of file on the local machine after transfer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1502
may be different.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1503
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1504
=item supported ( CMD )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1505
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1506
Returns TRUE if the remote server supports the given command.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1507
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1508
=item hash ( [FILEHANDLE_GLOB_REF],[ BYTES_PER_HASH_MARK] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1509
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1510
Called without parameters, or with the first argument false, hash marks
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1511
are suppressed.  If the first argument is true but not a reference to a 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1512
file handle glob, then \*STDERR is used.  The second argument is the number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1513
of bytes per hash mark printed, and defaults to 1024.  In all cases the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1514
return value is a reference to an array of two:  the filehandle glob reference
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1515
and the bytes per hash mark.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1516
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1517
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1518
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1519
The following methods can return different results depending on
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1520
how they are called. If the user explicitly calls either
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1521
of the C<pasv> or C<port> methods then these methods will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1522
return a I<true> or I<false> value. If the user does not
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1523
call either of these methods then the result will be a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1524
reference to a C<Net::FTP::dataconn> based object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1525
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1526
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1527
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1528
=item nlst ( [ DIR ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1529
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1530
Send an C<NLST> command to the server, with an optional parameter.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1531
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1532
=item list ( [ DIR ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1533
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1534
Same as C<nlst> but using the C<LIST> command
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1535
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1536
=item retr ( FILE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1537
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1538
Begin the retrieval of a file called C<FILE> from the remote server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1539
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1540
=item stor ( FILE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1541
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1542
Tell the server that you wish to store a file. C<FILE> is the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1543
name of the new file that should be created.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1544
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1545
=item stou ( FILE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1546
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1547
Same as C<stor> but using the C<STOU> command. The name of the unique
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1548
file which was created on the server will be available via the C<unique_name>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1549
method after the data connection has been closed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1550
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1551
=item appe ( FILE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1552
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1553
Tell the server that we want to append some data to the end of a file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1554
called C<FILE>. If this file does not exist then create it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1555
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1556
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1557
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1558
If for some reason you want to have complete control over the data connection,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1559
this includes generating it and calling the C<response> method when required,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1560
then the user can use these methods to do so.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1561
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1562
However calling these methods only affects the use of the methods above that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1563
can return a data connection. They have no effect on methods C<get>, C<put>,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1564
C<put_unique> and those that do not require data connections.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1565
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1566
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1567
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1568
=item port ( [ PORT ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1569
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1570
Send a C<PORT> command to the server. If C<PORT> is specified then it is sent
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1571
to the server. If not, then a listen socket is created and the correct information
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1572
sent to the server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1573
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1574
=item pasv ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1575
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1576
Tell the server to go into passive mode. Returns the text that represents the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1577
port on which the server is listening, this text is in a suitable form to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1578
sent to another ftp server using the C<port> method.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1579
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1580
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1581
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1582
The following methods can be used to transfer files between two remote
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1583
servers, providing that these two servers can connect directly to each other.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1584
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1585
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1586
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1587
=item pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1588
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1589
This method will do a file transfer between two remote ftp servers. If
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1590
C<DEST_FILE> is omitted then the leaf name of C<SRC_FILE> will be used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1591
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1592
=item pasv_xfer_unique ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1593
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1594
Like C<pasv_xfer> but the file is stored on the remote server using
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1595
the STOU command.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1596
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1597
=item pasv_wait ( NON_PASV_SERVER )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1598
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1599
This method can be used to wait for a transfer to complete between a passive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1600
server and a non-passive server. The method should be called on the passive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1601
server with the C<Net::FTP> object for the non-passive server passed as an
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1602
argument.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1603
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1604
=item abort ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1605
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1606
Abort the current data transfer.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1607
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1608
=item quit ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1609
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1610
Send the QUIT command to the remote FTP server and close the socket connection.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1611
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1612
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1613
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1614
=head2 Methods for the adventurous
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1615
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1616
C<Net::FTP> inherits from C<Net::Cmd> so methods defined in C<Net::Cmd> may
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1617
be used to send commands to the remote FTP server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1618
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1619
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1620
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1621
=item quot (CMD [,ARGS])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1622
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1623
Send a command, that Net::FTP does not directly support, to the remote
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1624
server and wait for a response.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1625
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1626
Returns most significant digit of the response code.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1627
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1628
B<WARNING> This call should only be used on commands that do not require
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1629
data connections. Misuse of this method can hang the connection.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1630
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1631
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1632
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1633
=head1 THE dataconn CLASS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1634
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1635
Some of the methods defined in C<Net::FTP> return an object which will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1636
be derived from this class.The dataconn class itself is derived from
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1637
the C<IO::Socket::INET> class, so any normal IO operations can be performed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1638
However the following methods are defined in the dataconn class and IO should
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1639
be performed using these.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1640
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1641
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1642
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1643
=item read ( BUFFER, SIZE [, TIMEOUT ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1644
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1645
Read C<SIZE> bytes of data from the server and place it into C<BUFFER>, also
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1646
performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1647
given, the timeout value from the command connection will be used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1648
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1649
Returns the number of bytes read before any <CRLF> translation.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1650
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1651
=item write ( BUFFER, SIZE [, TIMEOUT ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1652
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1653
Write C<SIZE> bytes of data from C<BUFFER> to the server, also
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1654
performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1655
given, the timeout value from the command connection will be used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1656
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1657
Returns the number of bytes written before any <CRLF> translation.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1658
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1659
=item bytes_read ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1660
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1661
Returns the number of bytes read so far.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1662
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1663
=item abort ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1664
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1665
Abort the current data transfer.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1666
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1667
=item close ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1668
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1669
Close the data connection and get a response from the FTP server. Returns
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1670
I<true> if the connection was closed successfully and the first digit of
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1671
the response from the server was a '2'.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1672
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1673
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1674
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1675
=head1 UNIMPLEMENTED
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1676
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1677
The following RFC959 commands have not been implemented:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1678
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1679
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1680
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1681
=item B<SMNT>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1682
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1683
Mount a different file system structure without changing login or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1684
accounting information.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1685
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1686
=item B<HELP>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1687
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1688
Ask the server for "helpful information" (that's what the RFC says) on
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1689
the commands it accepts.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1690
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1691
=item B<MODE>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1692
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1693
Specifies transfer mode (stream, block or compressed) for file to be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1694
transferred.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1695
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1696
=item B<SYST>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1697
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1698
Request remote server system identification.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1699
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1700
=item B<STAT>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1701
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1702
Request remote server status.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1703
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1704
=item B<STRU>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1705
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1706
Specifies file structure for file to be transferred.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1707
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1708
=item B<REIN>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1709
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1710
Reinitialize the connection, flushing all I/O and account information.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1711
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1712
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1713
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1714
=head1 REPORTING BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1715
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1716
When reporting bugs/problems please include as much information as possible.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1717
It may be difficult for me to reproduce the problem as almost every setup
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1718
is different.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1719
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1720
A small script which yields the problem will probably be of help. It would
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1721
also be useful if this script was run with the extra options C<Debug => 1>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1722
passed to the constructor, and the output sent with the defect report. If you
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1723
cannot include a small script then please include a Debug trace from a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1724
run of your program which does yield the problem.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1725
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1726
=head1 AUTHOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1727
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1728
Graham Barr <gbarr@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1729
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1730
=head1 SEE ALSO
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1731
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1732
L<Net::Netrc>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1733
L<Net::Cmd>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1734
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1735
ftp(1), ftpd(8), RFC 959
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1736
http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1737
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1738
=head1 USE EXAMPLES
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1739
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1740
For an example of the use of Net::FTP see
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1741
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1742
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1743
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1744
=item http://www.csh.rit.edu/~adam/Progs/
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1745
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1746
C<autoftp> is a program that can retrieve, send, or list files via
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1747
the FTP protocol in a non-interactive manner.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1748
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1749
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1750
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1751
=head1 CREDITS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1752
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1753
Henry Gabryjelski <henryg@WPI.EDU> - for the suggestion of creating directories
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1754
recursively.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1755
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1756
Nathan Torkington <gnat@frii.com> - for some input on the documentation.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1757
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1758
Roderick Schertler <roderick@gate.net> - for various inputs
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1759
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1760
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1761
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1762
Copyright (c) 1995-1998 Graham Barr. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1763
This program is free software; you can redistribute it and/or modify it
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1764
under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1765
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1766
=for html <hr>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1767
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1768
I<$Id: //depot/libnet/Net/FTP.pm#80 $>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1769
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1770
=cut