Page 1 of 1

Php and FTP

Posted: Sun May 19, 2002 2:28 pm
by fatal
My current project is making a FTP client in PHP. I read up on the functions in the manual, and whatnot. I can connect to an FTP, i dont get any errors doing so. But the problem is when i try to get PHP to list the directory, nothing shows up.

Heres my code

Code: Select all

<?php
		$connect = ftp_connect( $_POST&#1111;'server'], $_POST&#1111;'port'] );
		if( !$connect )
		&#123;
			echo"Couldnt connect to the server: $server";
			exit;
		&#125;
		
		$login = ftp_login($connect, $_POST&#1111;'user'], $_POST&#1111;'pass']);
		if( !$login )
		&#123;
			echo"Invalid Login Info";
			exit;
		&#125;
		
		$dir = ftp_pwd($connect); 
		$list=Array(); 
		$list=ftp_nlist($connect, "$dir");
		$i=0;
		do&#123; 
    		echo $list&#1111;$i]; 
			$i++;
		&#125;while($list&#1111;$i]);
	?>
And also i did enable FTP in php.ini

Posted: Mon May 20, 2002 11:20 am
by cwcollins
try using ftp_rawlist(). it seems like this function is a little more reliable.

Posted: Mon May 20, 2002 12:29 pm
by fatal
:D Worked nicely, one more thing. Is there another function besides 'ftp_chdir()' that will display links to the directory?

Posted: Mon May 20, 2002 1:41 pm
by cwcollins
you may be able to make ftp_rawlist() do it for you...

http://www.php.net/manual/en/function.ftp-rawlist.php

-c.w.collins