Jump to content

FTP Problems


dyluck

Recommended Posts

Trying to connect to FTP.

With one host, it works fine and lists all the files, with another, all it returns is the host server name.

 

function ftpdirectory( $host, $username, $password, $directory ) { 
// set up a connection or die
$conn = ftp_connect($host) or die("Couldn't connect to $ftp_server"); 

if (ftp_login($conn, $username, $password))
   	 	{
	ftp_pasv($conn, true);
        // Change the dir

	if(@ftp_chdir( $conn, $directory )) {  ftp_chdir($conn, $directory);      } 
        		
	$ftp_nlist = ftp_nlist($conn, ".");
	sort($ftp_nlist);
	$x = 0;
	$neg = "-1";

	foreach ($ftp_nlist as $v) {

	//1. Size is '-1' => directory
		 if (ftp_size($ftp_connect, $v) == $neg) {

	//output as [ directory ]
     	 $flist[$x] = $v;
				$x++;
			}
		}

	foreach ($ftp_nlist as $v) {

	//2. Size is not '-1' => file
  		if (ftp_size($ftp_connect, $v) <> $neg) {

	//output as file
      	$flist[$x] = $v;
		 $x++;
	 }
	}
	//ftp_close($conn);	
	return $flist;
        ftp_close($conn);
    	}  else { return false; ftp_close($conn); }

}

echo implode("<br>", ftpdirectory( $host,$username,$password,$directory));

 

No matter what I get a long list of the following error on the one that works:

Warning: ftp_size() expects parameter 1 to be resource, null given in

 

The one that doesn't work does this:

Warning: ftp_size() expects parameter 1 to be resource, null given in /home/public_html/test/testfunctions.php on line 89

Warning: ftp_size() expects parameter 1 to be resource, null given in /home/public_html/test/testfunctions.php on line 100

ftp.host.com

 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/208134-ftp-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.