Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
// <!--<?php-->
// <!--header('Content-Type: application/json;charset=utf-8');-->
// // FTP 服务器信息
// $ftp_server = "101.43.223.180"; // FTP 服务器地址
// $ftp_user = "duoletest"; // FTP 用户名
// $ftp_pass = "iC5sQ2eZ3tI7kM9cD6"; // FTP 密码
// $remote_path = "/home/duoletest/tmp"; // 指定路径
// // 连接 FTP 服务器
// <!--$conn_id = ftp_connect($ftp_server);-->
// // 登录到 FTP 服务器
// <!--$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);-->
// // 检查连接是否成功
// <!--if ((!$conn_id) || (!$login_result)) {-->
// <!-- die('{"error": "无法连接到 FTP 服务器"}');-->
// <!--}-->
// // 设置被动模式
// <!--ftp_pasv($conn_id, true);-->
// // 获取指定路径下的文件列表
// <!--$file_list = ftp_nlist($conn_id, $remote_path);-->
// // 获取文件详细信息
// <!--$file_details = [];-->
// <!--foreach ($file_list as $file) {-->
// <!-- $file_info = ftp_rawlist($conn_id, $file);-->
// <!-- if (is_array($file_info)) {-->
// <!-- $file_info = $file_info[0];-->
// <!-- preg_match('/^([drwx-]{10})\s+(\d+)\s+([a-zA-Z0-9_]+)\s+([a-zA-Z0-9_]+)\s+([0-9]+)\s+([a-zA-Z]{3})\s+(\d+)\s+(\d+):(\d+)\s+(.*)$/i', $file_info, $matches);-->
// <!-- $file_details[] = [-->
// <!-- 'name' => $matches[10],-->
// <!-- 'type' => $matches[1],-->
// <!-- 'size' => $matches[5],-->
// <!-- 'modified_date' => $matches[6] . ' ' . $matches[7] . ' ' . $matches[8] . ':' . $matches[9]-->
// <!-- ];-->
// <!-- }-->
// <!--}-->
// <!--ftp_close($conn_id);-->
// <!--echo json_encode($file_details);-->
// <!--?>-->
<?php
// FTP 服务器配置
$ftp_server = '101.43.223.180'; // FTP 服务器地址
$ftp_username = 'duoletest'; // FTP 用户名
$ftp_password = 'iC5sQ2eZ3tI7kM9cD6'; // FTP 密码(请替换为实际密码)
// 连接到 FTP 服务器
$conn_id = ftp_connect($ftp_server);
// 使用用户名和密码登录
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
// 检查连接是否成功
if ((!$conn_id) || (!$login_result)) {
die('无法连接到 FTP 服务器: ' . $ftp_server);
} else {
echo '成功连接到 FTP 服务器: ' . $ftp_server . "\n";
}
// 设置被动模式(通常更安全)
ftp_pasv($conn_id, true);
// 获取目录中的文件列表
$files = ftp_nlist($conn_id, '.');
// 打印文件列表
echo '目录中的文件列表: ' . "\n";
print_r($files);
// 关闭 FTP 连接
ftp_close($conn_id);
?>