note 46865 added to function.ftp-login

From: Date: Tue, 26 Oct 2004 08:37:14 +0000
Subject: note 46865 added to function.ftp-login
Groups: php.notes 
Request: Send a blank email to php-notes+get-79114@lists.php.net to get a copy of this message
ftp_login does not support ftp trough proxy authentication. So think about using the new PHP5 function ftp_raw() that's allow you to send directly FTP commands. ftp_raw() allow you to send commands prior to be connected (unlike ftp_exec()). I've writen this piece of code that's allow you to connect through a "remoteid@remotehost proxyid" proxy. <?php function ftp_parse_response($response, &$errstr) { if(!is_array($response)) { $errstr = 'Parameter \$response must be an array'; return false; } foreach($response as $r) { $code = substr(trim($r),0,3); if(!is_numeric($code)) { $errstr = "$code is not a valid FTP code",$code); } if($code > 400) { $errstr = $r; return false; } } return true; } $user = "user"; $pass = "password"; $host = "ftp.example.com"; $proxyuser = "proxyuser"; $proxypass = "proxypass"; $proxyhost = "ftp.proxy.com"; $conn_id = ftp_connect($proxyhost); if(!$conn_id) { die("cannot connect to proxy"); } $commands = array( "USER ".$user."@".$host." ".$proxyuser, "PASS ".$pass, "PASS ".$proxypass ); foreach($commands as $c) { $ret = ftp_raw($conn_id,$c); //you can write your own ftp_parse_response func that //use an array of string as input if(!ftp_parse_response($ret,$errstr)) { ftp_close($conn_id); die("cannot login to $host"); } } echo "ok, now connected"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.ftp-login.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46865 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46865&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46865&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46865&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46865&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46865&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46865&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46865&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79114) next »