Php and FTP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
fatal
Forum Contributor
Posts: 118
Joined: Sat Apr 20, 2002 10:47 am
Location: East Coast

Php and FTP

Post 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
User avatar
cwcollins
Forum Commoner
Posts: 79
Joined: Thu May 16, 2002 3:51 pm
Location: Milwaukee, WI, USA

Post by cwcollins »

try using ftp_rawlist(). it seems like this function is a little more reliable.
User avatar
fatal
Forum Contributor
Posts: 118
Joined: Sat Apr 20, 2002 10:47 am
Location: East Coast

Post by fatal »

:D Worked nicely, one more thing. Is there another function besides 'ftp_chdir()' that will display links to the directory?
User avatar
cwcollins
Forum Commoner
Posts: 79
Joined: Thu May 16, 2002 3:51 pm
Location: Milwaukee, WI, USA

Post 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
Post Reply