Commit 10fdb1d7 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

EPSV and SIZE adjustments

parent f0d3fccd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ filter off really nothing
USER anonymous
PASS curl_by_daniel@haxx.se
PWD
PASV
EPSV
TYPE A
LIST
</protocol>
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ FTP RETR PASV
ftp://%HOSTIP:%FTPPORT/102
</command>
</test>
<file name="log/ftpserver.cmd">
REPLY EPSV 500 no such command
</file>


# Verify data after the test has been "shot"
<verify>
@@ -26,8 +30,10 @@ ftp://%HOSTIP:%FTPPORT/102
USER anonymous
PASS curl_by_daniel@haxx.se
PWD
EPSV
PASV
TYPE I
SIZE 102
RETR 102
</protocol>
</verify>
+34 −5
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ my %commandok = (
                 'USER' => 'fresh',
                 'PASS' => 'passwd',
                 'PASV' => 'loggedin|twosock',
                 'EPSV' => 'loggedin|twosock',
                 'PORT' => 'loggedin|twosock',
                 'TYPE' => 'loggedin|twosock',
                 'LIST' => 'twosock',
@@ -86,6 +87,7 @@ my %statechange = ( 'USER' => 'passwd', # USER goes to passwd state
                    'PASS' => 'loggedin',  # PASS goes to loggedin state
                    'PORT' => 'twosock',   # PORT goes to twosock
                    'PASV' => 'twosock',   # PASV goes to twosock
                    'EPSV' => 'twosock',   # EPSV goes to twosock
                    );

# this text is shown before the function specified below is run
@@ -108,6 +110,7 @@ my %commandfunc = ( 'PORT' => \&PORT_command,
                    'LIST' => \&LIST_command,
                    'NLST' => \&NLST_command,
                    'PASV' => \&PASV_command,
                    'EPSV' => \&PASV_command,
                    'RETR' => \&RETR_command,   
                    'SIZE' => \&SIZE_command,
                    'REST' => \&REST_command,
@@ -169,6 +172,16 @@ sub SIZE_command {

    my $size = $data[0];

    if($size) {
        print "213 $size\r\n";
        logmsg "SIZE $testno returned $size\n";
    }
    else {
        $size=0;
        @data = getpart("reply", "data");
        for(@data) {
            $size += length($_);
        }
        if($size) {
            print "213 $size\r\n";
            logmsg "SIZE $testno returned $size\n";
@@ -177,6 +190,7 @@ sub SIZE_command {
            print "550 $testno: No such file or directory.\r\n";
            logmsg "SIZE $testno: no such file\n";
        }
    }
    return 0;
}

@@ -259,6 +273,8 @@ sub STOR_command {

my $pasvport=9000;
sub PASV_command {
    my ($arg, $cmd)=@_;

    socket(Server2, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
    setsockopt(Server2, SOL_SOCKET, SO_REUSEADDR,
               pack("l", 1)) || die "setsockopt: $!";
@@ -283,8 +299,17 @@ sub PASV_command {
    }
    listen(Server2,SOMAXCONN) || die "listen: $!";

    if($cmd ne "EPSV") {
        # PASV reply
        logmsg "replying to a $cmd command\n";
        printf("227 Entering Passive Mode (127,0,0,1,%d,%d)\n",
               ($pasvport/256), ($pasvport%256));
    }
    else {
        # EPSV reply
        logmsg "replying to a $cmd command\n";
        printf("229 Entering Passive Mode (|||%d|)\n", $pasvport);
    }

    my $paddr = accept(SOCK, Server2);
    my($iport,$iaddr) = sockaddr_in($paddr);
@@ -297,6 +322,7 @@ sub PASV_command {
    return;
}


sub PORT_command {
    my $arg = $_[0];

@@ -432,6 +458,9 @@ for ( $waitedpid = 0;
        if($text eq "") {
            $text = $displaytext{$FTPCMD};
        }
        else {
            logmsg "$FTPCMD made to send '$text'\n";
        }
        if($text) {
            print "$text\r\n";
        }
@@ -442,7 +471,7 @@ for ( $waitedpid = 0;
            my $func = $commandfunc{$FTPCMD};
            if($func) {
                # it is!
                \&$func($FTPARG);
                \&$func($FTPARG, $FTPCMD);
            }
        }