Hi:
The problem is because althought I have PHP 4.2 installed, the host have not activated the --enable-ftp attribute, so i dont have the FTP commands of PHP.
So, I want to store a file with socket. I have read in php.net fopen page that I can do in this way:
$ftp=fsockopen("xx.xx.xx.xx",21);
echo "<br>".fgets($ftp,255);
fputs($ftp,"USER xxxxxxxx\r\n");
echo "<br>".fgets($ftp,255);
fputs($ftp,"PASS *******\r\n");
echo "<br>".fgets($ftp,255);
fputs($ftp,"MKD directory\r\n");
echo "<br>".fgets($ftp,255);
fputs($ftp,"TYPE A\r\n");
echo "<br>".fgets($ftp,255);
fputs($ftp,"PASV\r\n");
echo "<br>".fgets($ftp,255);
fputs($ftp,"STOR file.html\r\n");
echo "<br>".fgets($ftp,255);
fputs($ftp,"QUIT\r\n");
echo "<br>".fgets($ftp,255);
fclose($ftp);
All goes well, the FTP response successfully, but when it tries to do the STOR command, the PHP hangs up, and it gives me timeout in a time...
I have debug line by line, and the problem (when it hangs) is exactly when fputs($ftp,"STOR file.html\r\n");
I have tested other lines as
fputs($ftp,"STOR file.html\r\n");
fputs($ftp,"STOR path-to-directory/file.html\r\n");
fputs($ftp,"STOR relative-path-to-directory/file.html\r\n");
I dont know the cause of hanging up... any ideas ? I NEED to do it with this way because i dont have FTP commands.
The fact is that when i do THE SAME from a linux shell, doing a telnet connection to port 21 and "talking" with the FTP in the same way, the problem IS THE SAME !!!!
The other way i have problems 🙂
Instead of doing a FTP session from host 1 to host 2, I thought to call a PHP with all the variables needed to create the file in host 2 directly. So I do a php in host 2 that create that file, but i have another problem:
umask(0);
mkdir ("directory", 777);
$fp = fopen("file.html","w");
This gives me error to:
Warning: SAFE MODE Restriction in effect. The script whose uid is 507 is not allowed to access /path-to-directory/directory owned by uid 48 in /path-to-directory/file.html on line 7
I have test with all kinda things
$fp = fopen("file.html","w");
$fp = fopen("path-todirectory/file.html","w");
$fp = fopen("relative-path-todirectory/file.html","w");
...
The umask(0) is put because (as i read in php.net forums) in this way you force to have the permission you select in mkdir command.
Any ideas to this ?
THANK YOU VERY MUCH in advance and sorry for this long email 😛