【发布时间】:2015-08-15 18:13:47
【问题描述】:
我在远程服务器上有一个用户文件夹(页面文件除外)。我需要检查整个“示例”文件夹的大小,而不是一个文件。我想我应该用 ftp 来做,但我不能。
我有类似的东西但不工作:
function dirFTPSize($ftpStream, $dir) {
$size = 0;
$files = ftp_nlist($ftpStream, $dir);
foreach ($files as $remoteFile) {
if(preg_match('/.*\/\.\.$/', $remoteFile) || preg_match('/.*\/\.$/', $remoteFile)){
continue;
}
$sizeTemp = ftp_size($ftpStream, $remoteFile);
if ($sizeTemp > 0) {
$size += $sizeTemp;
}elseif($sizeTemp == -1){//directorio
$size += dirFTPSize($ftpStream, $remoteFile);
}
}
return $size;
}
$hostname = '127.0.0.1';
$username = 'username';
$password = 'password';
$startdir = '/public_html'; // absolute path
$files = array();
$ftpStream = ftp_connect($hostname);
$login = ftp_login($ftpStream, $username, $password);
if (!$ftpStream) {
echo 'Wrong server!';
exit;
} else if (!$login) {
echo 'Wrong username/password!';
exit;
} else {
$size = dirFTPSize($ftpStream, $startdir);
}
echo number_format(($size / 1024 / 1024), 2, '.', '') . ' MB';
ftp_close($ftpStream);
整个时间脚本显示 0.00 MB,我该如何解决?
【问题讨论】:
-
对,但我需要连接到另一台托管服务器。我编辑我的问题我添加了一个 php 代码
-
你有远程服务器上的 SSH 访问权限吗?
-
是的,我可以访问远程服务器上的 SSH 控制台。