Note that to make an anonymous ftp connection, you need to specify "anonymous" as the username and "" (empty string) as the password.
Example:
<?php
ftp_login('ftp.example.com', 'anonymous', '');
?>
ftp_login
(PHP 4, PHP 5)
ftp_login — FTP bağlantısında kullanıcı oturumu açar
Açıklama
bool ftp_login
( resource
$ftp_akımı
, string $kullanıcı
, string $parola
)Belirtilen FTP akımı üzerinde belirtilen kullanıcı için bir oturum açar.
Değiştirgeler
-
ftp_akımı -
FTP bağlantısının bağlantı tanıtıcısı.
-
kullanıcı -
Kullanıcı adı (FTP komutu: USER).
-
parola -
Parola (FTP komutu: PASS).
Dönen Değerler
Başarı durumunda TRUE, başarısızlık durumunda FALSE döner.
Oturum açılamazsa PHP bir uyarı çıktılar.
Örnekler
Örnek 1 - ftp_login() örneği
<?php
$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";
// bağlantıyı kuralım
$conn_id = ftp_connect($ftp_server) or die(
"$ftp_server sunucusuna bağlantı kurulamadı");
// oturum açmayı deneyelim
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "$ftp_user@$ftp_server oturumu açıldı\n";
} else {
echo "$ftp_user için oturum açılamadı\n";
}
// bağlantıyı kapatalım
ftp_close($conn_id);
?>
mattsch at gmail dot com
30-Nov-2010 01:12
Guibod
25-Oct-2004 07:37
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";
?>
