dyluck Posted July 19, 2010 Share Posted July 19, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/208134-ftp-problems/ Share on other sites More sharing options...
premiso Posted July 19, 2010 Share Posted July 19, 2010 I think $ftp_connect should be $conn. Quote Link to comment https://forums.phpfreaks.com/topic/208134-ftp-problems/#findComment-1087966 Share on other sites More sharing options...
dyluck Posted July 19, 2010 Author Share Posted July 19, 2010 excellent thanks haha silly me that got rid of the errors. Still is returning just the host name and not the list of files though Quote Link to comment https://forums.phpfreaks.com/topic/208134-ftp-problems/#findComment-1087968 Share on other sites More sharing options...
Kevin.Arvixe Posted July 19, 2010 Share Posted July 19, 2010 Use ftp_rawlist() Quote Link to comment https://forums.phpfreaks.com/topic/208134-ftp-problems/#findComment-1087969 Share on other sites More sharing options...
dyluck Posted July 19, 2010 Author Share Posted July 19, 2010 awesome works Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/208134-ftp-problems/#findComment-1087975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.