SunshinePHP Developer Conference 2015

Utilisation simple

Exemple #1 Exemple avec FTP

<?php
// Mise en place d'une connexion basique
$conn_id ftp_connect($ftp_server);

// Identification avec un nom d'utilisateur et un mot de passe
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

// Vérification de la connexion
if ((!$conn_id) || (!$login_result)) {
    echo 
"La connexion FTP a échoué !";
    echo 
"Tentative de connexion au serveur $ftp_server pour l'utilisateur $ftp_user_name";
    exit;
} else {
    echo 
"Connexion au serveur $ftp_server, pour l'utilisateur $ftp_user_name";
}

// Chargement d'un fichier
$upload ftp_put($conn_id$destination_file$source_fileFTP_BINARY); 

// Vérification du status du chargement
if (!$upload) {
    echo 
"Le chargement FTP a échoué!";
} else {
    echo 
"Chargement de $source_file vers $ftp_server en tant que $destination_file";
}

// Fermeture du flux FTP
ftp_close($conn_id);
?>

add a note add a note

User Contributed Notes 2 notes

up
2
kane dot prajakta at gmail dot com
4 years ago
I used following code successfully to connect to "lftp" server and see the complete dir listing.
also ftp_pasv($conn_id, true); trick works fine for lftp server :)

<?php
// set up basic connection
$ftp_server = "example.com";
$conn_id = ftp_ssl_connect($ftp_server);

// login with username and password
$ftp_user_name = "myuser";
$ftp_user_pass = "mypass";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
// check connection
if ((!$conn_id) || (!$login_result)) {
        echo
"FTP connection has failed!";
        echo
"Attempted to connect to $ftp_server for user $ftp_user_name";
        exit;
    } else {
        echo
"Connected to $ftp_server, for user $ftp_user_name";
    }

$buff = ftp_rawlist($conn_id, '.');
var_dump($buff);
ftp_close($conn_id); 
?>

Thanks ,
Prajakta
up
0
clemensroth2004 at yahoo dot de
5 years ago
My FTP-Server always responded "bool(false)" instead of presenting me a directory-listing. I had to add
ftp_pasv($conn_id, true); right after the $login_result = ftp_login(...); line.
After that it just worked fine.
To Top