0

我正在尝试从远程服务器打开一个文件夹。我写 :

if ($folderHandle = opendir($folder))

在哪里$folder = "ftp://xxx:xxx@xxx.net:21"

我得到了奇怪的错误Warning: opendir(ftp://...:21): failed to open dir: operation failed in ... on line 38

关于我应该从这里去哪里的任何想法?FTP凭据有问题吗?

4

1 回答 1

1

您可以使用 PHP 的FTP 功能远程连接到服务器并获取目录列表:

// set up basic connection
$conn_id = ftp_connect('otherserver.example.com'); 

// login with username and password
$login_result = ftp_login($conn_id, 'username', 'password'); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!";
    exit; 
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

// check upload status
if (!$upload) { 
    echo "FTP upload has failed!";
} else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// Retrieve directory listing
$files = ftp_nlist($conn_id, '/remote_dir');

// close the FTP stream 
ftp_close($conn_id);
于 2012-04-19T11:56:09.270 回答