note 39448 added to function.fopen

From: Date: Thu, 29 Jan 2004 04:34:38 +0000
Subject: note 39448 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-64344@lists.php.net to get a copy of this message
If you are connecting to your ftp server through a router doing NAT (such as the Zyxel 128L prestige router/bridge we are using) by doing say an <? fopen("ftp://ftpusername:ftppassword@ftpserver/".$file_name, "w") ?>, then this could fail. You will get php_hostconnect connection failed error. This is because <?fopen() ?>function uses a passive ftp connection which the Zyxel router does not support, even though your ftp server may be configured to allow the passive connections which php <?fopen?> function is using. Note that $file_name is the file we want to ftp to the remote server eg could be file.txt. Thus an alternative would be to do create the file you want in a local directory of your machine or in the webserver where your php files reside eg use <?fwrite()?> as documented in the manual. Once you have the $file_name you want to ftp created, do the following: <? ftp_connect($ftp_server); //which can connect to the ftp server using an active connection. ftp_login ($conn_id, $ftp_username."@".$ftp_server, $ftp_password); $fp = fopen($PATH."".$file_name, 'r'); // eg. $fp = fopen("http://www.yourwebsite.com/".$file_name, 'r'); //turn off passive mode transfers ftp_pasv ($conn_id, false); //now upload $file_name ftp_fput($conn_id, $file_name, $fp, FTP_ASCII)); ?> Your file should now be in your ftp server, having used an active connection. ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39448 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39448&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39448&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64344) next »