WTF am i doing wrong?

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
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

WTF am i doing wrong?

Post by Jose Arce »

Code: Select all

$conexion = pfsockopen("$ft_ip", "$ft_port");
	echo "$ft_ip<br>" ;
	echo "<br><table width=90% cellspacing=1 cellpadding=3 border=0 align=center><tr><td class=codigo>" ;
		@fputs($conexion,"USER $ft_user\r\n<br>");
	echo @fgets($conexion,331);
	echo "<br>" ;
		@fputs($conexion,"PASS $ft_pass\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fputs($conexion,"TYPE I\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fputs($conexion, "REST 100\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fputs($conexion, "REST 0\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fputs($conexion,"CWD $ft_dir\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fputs($conexion,"PASS\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fputs($conexion,"RETR $ft_file\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fputs($conexion,"QUIT\r\n<br>");
	echo @fgets($conexion,256);
	echo "<br>" ;
		@fclose ($conexion) ;
	echo "</td></tr></table>" ;
Now...what am i doing wrong, because it's not working... :( :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

have you ever watched the console-ouput of your ftp-client? here's the list-command for example
> PORT 217,89,121,72,15,64
< 200 PORT command successful.
> TYPE A
< 200 Type set to A.
> LIST
< 150 Opening ASCII mode data connection for /bin/ls.
< 226 Transfer complete.
note the port command. It lets the ftp-server know to where the output should be sent. The server will open a connection to the client on the specified ip&port. It's the same with retrieving a file. There is a PASV-command used by the client to tell the server it is in passive mode. In passive mode the client initiates both connections (control and data) to the server, but there are still two sockets used.
It's probably simpler to use the php ftp functions as long as enable-ftp is On

a short overview on ftp (active vs. passive) can be found here. It also has a referrence to the ftp-protocol-RFC 959
Post Reply