note 52630 added to ref.ftp

From: Date: Sat, 07 May 2005 15:20:43 +0000
Subject: note 52630 added to ref.ftp
Groups: php.notes 
Request: Send a blank email to php-notes+get-89080@lists.php.net to get a copy of this message
It may seem obvious to others, but it had me stumped for nearly an hour! If you can connect to an ftp site but some functions (list, put, get etc) don't work, then try using ftp_pasv and set passive mode on. <?php // setup $host and $file variables for your setup before here... $hostip = gethostbyname($host); $conn_id = ftp_connect($hostip); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // IMPORTANT!!! turn passive mode on ftp_pasv ( $conn_id, true ); if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $host for user $ftp_user_name"; die; } else { echo "Connected to $host, for user $ftp_user_name<br>"; echo "Host IP is $hostip<br>"; // upload a file if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) { echo "successfully uploaded $file<br>"; } else { echo "There was a problem while uploading $file<br>"; } // close the connection ftp_close($conn_id); } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.ftp.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52630 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52630&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52630&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52630&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52630&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52630&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52630&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89080) next »