FTP errors from PHP

elohim

New Member
Prime Account
Messages
17
Reaction score
0
Points
1
I am trying to use FTP from my PHP program to read a directory.

ftp_nlist returns Bool(False)

Some PHP sites suggest to set ftp_pasv to TRUE after the login, when I do that now I get tihs error:

Warning: ftp_nlist() [function.ftp-nlist]: php_connect_nonb() failed: Operation now in progress (115) in ....php on line 43

Thanks

---------- Post added at 07:01 PM ---------- Previous post was at 06:01 PM ----------

Sorry, forgot to include the code sample:

PHP:
 $fconn_id = ftp_connect($ftp_host);
 $login = ftp_login($fconn_id, $ftp_user, $ftp_password);
 ftp_set_option($fconn_id, FTP_TIMEOUT_SEC, 10);
 $mode = ftp_pasv($fconn_id, TRUE);
 if ((!$fconn_id) || (!$login) || (!$mode)) {
  die("FTP connection failed.");
 }
 $mode = ftp_pasv($fconn_id, TRUE);
 $file_list = ftp_nlist($fconn_id, ".");
 var_dump($file_list);
 ftp_close($fconn_id);

This gives me a timeout (after 10 seconds):
Warning: ftp_nlist() [function.ftp-nlist]: php_connect_nonb() failed: Operation now in progress (115) in /home/elohim/public_html/pkStats/load_xml.php on line 42
bool(false)

If I comment out the ftp_pasv lines, then I get (immediately):
bool(false)

Any ideas?
Thanks
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Are you connecting to a local FTP server? If you are, there's much easier ways to achieve this without FTP..

Also, if you're connecting to a remote server, why not just write a script on the remote server and use CURL to get that script...
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
For debuging here is a non PHP/FTP I use to list files in a directory
put it "as is" in a directory then call it from you browser
or set ==>$dirPath<==

PHP:
<?php

// To list the content of a directory you just need to use the combination
// of opendir() and readdir() functions.
// directory path can be either absolute or relative
$dirPath = '.';
$listRHD = array();

// open the specified directory and check if it's opened successfully
if ($handle = opendir($dirPath))
  {
    print getcwd() . "<br />\n";

    // keep reading the directory entries 'til the end
    while (false !== ($file = readdir($handle)))
      {
        // just skip the reference to current and parent directory
        if ($file !== "." && $file !== "..")
          {
            if (is_dir("$dirPath/$file"))
              {
                  // found a directory, do something with it?
                  $listRHD[] = "[" . $file . "]";
              }
              else
                {
                  // found an ordinary file
                  $listRHD[] = $file;
                }
          }
      }

    sort($listRHD);

    foreach ($listRHD as $key => $val)
      {
        print $val . "<br />\n";
      }

   // ALWAYS remember to close what you opened
   closedir($handle);
  }
  else
    {
      print "ERROR on opendir<br />\n";
    }

print "-EOF-<br />\n";

?>
 
Top