Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.