php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14052 ftp_rawlist: Hangs up
Submitted: 2001-11-14 09:48 UTC Modified: 2002-07-10 22:48 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:0 (0.0%)
From: msjackson at bluemail dot ch Assigned:
Status: Closed Package: FTP related
PHP Version: 4.1.1 OS: Win2K
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: msjackson at bluemail dot ch
New email:
PHP Version: OS:

 

 [2001-11-14 09:48 UTC] msjackson at bluemail dot ch
I think there is really a problem with repeated ftp_rawlist (Reported in #7897). I write a script which make several ftp_rawlists to indexing all the content. In most case, the task "hangs up" for 1 or 2 minutes. Then the program will continue, but it can be that it hangs up again. When I start the script directly (cmd-line), it will run well. But when I start it trough the task scheduler or the web server, it hangs up always. I can't explain the problem more, because this is all -> Repeated ftp_rawlist, script is running under user "system".

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-02 09:46 UTC] mfischer@php.net
Is this bug still present to you, also with 4.1.0?

If so, can you verify that the 'hang' time is about 90 seconds (its a fixed coded timeout value in ext/ftp)?
 [2002-01-09 11:06 UTC] msjackson at bluemail dot ch
Yes I've tested it with 4.1.1 and the problem ist still present. 90 Seconds is absolutly true! In this time he hangs in the ftp_rawlist function... and then he will continue, but often doesn't work the next call to ftp_rawlist too. And sorry, it isn't a problem of the user, but when executing per CLI, the script run more reliable than executed by apache. When I start the script directly it run sometimes until end (Not often). 

I tested it on 2 machines (W2K-Notebook and W2K-PC). 

I'm very intrested in this function, because i'm working on a little web-filesharing-tool, which should index content of ftps. Thanks for your feedback!
 [2002-01-09 11:31 UTC] mfischer@php.net
I'm setting this to open, version to 4.1.1. Although in CVS there exists now a way to adjust the timeout (ftp_set_option(FTP_TIMEOUT_SEC, 10); for example) it's not a solution and there are still some flaws in the implementation IMO.
 [2002-01-09 11:32 UTC] yohgaki@php.net
Please update version :)
 [2002-01-20 19:35 UTC] erik at 1000mbit dot nl
Having the same problem here with WinXP proffesional
version 4.1.1

from my experience it seems it sends the "list" command.
then my FTP server (UNIX: type L8) receives it properly and
answers with the data being send in ASCii mode. and
then it hangs and i actually have to reboot for it to work
another time. It just won't interprete the script anymore
for a second there it allmost seems as if it needs to flush or waits for a timeout to occur.
 [2002-01-22 21:23 UTC] kofaldt at basic-vision dot com
I had the same problem with linux and PHP 4.1.1.

In my opinion there's a problem in line 886 of file ext/ftp/ftp.c. I replaced

memmove(ftp->inbuf, ftp->inbuf+4, FTP_BUFSIZE-4);

with

memmove(ftp->inbuf, ftp->inbuf+4, FTP_BUFSIZE-4);
if (ftp->extra)
    ftp->extra -= 4;

The execution of memmove drops 4 bytes of the last response text which is stored in ftp->inbuf. In case of ftp->extra != NULL, there are extra characters and 4 characters of the next response are lost if you don't adjust ftp->extra.
 [2002-07-03 11:27 UTC] carldrinkwater at mac dot com
This is still an issue.

Find below a test script which does a recursive directory listing of a FTP server.

This hangs on ProFTPd (Tested on >1.2.2) for the timeout period every so often on the ftp_rawlist (It seems mostly to be empty directories, but not always) but will usually continue working on the second or third retry.

It seems OK on other FTP servers, but I've not been able to really test this.

The FTP server logs indicate that the LIST has finished and has been transmitted.

The fix by resolves this issue, I will post a patch against 4.3.0-dev in a seperate comment.

===============================

<?
  $ConnId = ftp_connect( "localhost" );
  $LoginId = ftp_login( $ConnId, "carl", "passwd" );

  if ( !$ConnId || !$LoginId ) {
    echo "Login failed!\n";
    die();
  }

  ftp_pasv( $ConnId, true );

  function doDirectory( $Path, $Depth ) {
    global $ConnId;

    echo str_repeat( " ", $Depth );
    echo "'$Path'\n";

    ftp_chdir( $ConnId, $Path );
    unset($ThisPath);
    $i = 1;
    while ( !is_array( $ThisPath ) ) {
      $ThisPath = ftp_rawlist( $ConnId, "-al" );
      if ( !is_array( $ThisPath ) ) {
        echo str_repeat( " ", $Depth+2 );
        echo "*** Error, Retrying ".($i++)." ...\n";
      }
    }

    foreach( $ThisPath AS $Entry ) {
      if( ereg( "([-d])[rwxst-]{9}.* ([0-9]*) [a-zA-Z]+ [0-9: ]*[0-9] (.+)", $Entry, $Bits ) ) {

        if ( $Bits[3] == "." || $Bits[3] == ".." ) {
          continue;
        }

        if ( $Bits[1] == "d" ) {
          doDirectory( $Bits[3], $Depth+2 );

        } else {
          echo str_repeat( " ", $Depth+2 );
          echo $Bits[3]."\n";

        }

      } ## Matches the ereg?

    } ## Iterate directory entries

    ftp_chdir( $ConnId, ".." );

  } ## End doDirectory()

  doDirectory( "", 0 );
?>
 [2002-07-03 11:30 UTC] carl at topthetable dot com
Here is the aforementioned patch ...

======================

Index: ftp.c
===================================================================
RCS file: /repository/php4/ext/ftp/ftp.c,v
retrieving revision 1.49
diff -u -r1.49 ftp.c
--- ftp.c       18 Mar 2002 22:26:32 -0000      1.49
+++ ftp.c       3 Jul 2002 15:28:36 -0000
@@ -919,6 +919,8 @@
                        (ftp->inbuf[2] - '0');
 
        memmove(ftp->inbuf, ftp->inbuf + 4, FTP_BUFSIZE - 4);
+  if ( ftp->extra )
+               ftp->extra -= 4;
 
        return 1;
 }
 [2002-07-10 22:48 UTC] sniper@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

Patch applied.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC