Page 1 of 1

WTF am i doing wrong?

Posted: Thu Jul 04, 2002 7:36 pm
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... :( :(

Posted: Thu Jul 04, 2002 8:02 pm
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