note 95661 modified in ftp.examples-basic by thiago
| From: | thiago@php.net | Date: | Thu, 14 Jan 2010 13:11:26 +0000 |
| Subject: | note 95661 modified in ftp.examples-basic by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164967@lists.php.net to get a copy of this message | ||
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
--was--
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 = "abc.myserver.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
http://php.net/manual/en/ftp.examples-basic.php