我正在通过命令行运行一个php脚本,它运行得很好,除了当它完成时,它不会回到命令行?只是坐在那里,所以我从来没有做过......
这是剧本:
$conn_id = ftp_connect(REMOTE)
or die("Couldn't connect to ".REMOTE);
$login_result = ftp_login($conn_id, 'OMITTED','OMITTED');
if ((!$conn_id) || (!$login_result))
die("FTP Connection Failed");
$dir = 'download';
if ($dir != ".") {
if (ftp_chdir($conn_id, $dir) == false) {
echo ("Change Dir Failed: $dir<BR>\r\n");
return;
}
if (!(is_dir($dir)))
mkdir($dir);
chdir ($dir);
}
$contents = ftp_nlist($conn_id, ".");
foreach ($contents as $file) {
if ($file == '.' || $file == '..')
continue;
if (@ftp_chdir($conn_id, $file)) {
ftp_chdir ($conn_id, "..");
ftp_sync ($file);
}
else
ftp_get($conn_id, $file, $file, FTP_BINARY);
}
ftp_chdir ($conn_id, "..");
chdir ("..");
ftp_close($conn_id);
答案 0 :(得分:0)
你错过了一些}
,一般来说,一些代码格式化使得阅读起来很困难。试试这个:
<?php
$conn_id = ftp_connect(REMOTE) or die("Couldn't connect to ".REMOTE);
$login_result = ftp_login($conn_id, 'OMITTED','OMITTED');
if ((!$conn_id) || (!$login_result))
die("FTP Connection Failed");
$dir = 'download';
if ($dir != ".") {
if (ftp_chdir($conn_id, $dir) == false) {
echo ("Change Dir Failed: $dir<BR>\r\n");
return;
}
if (!(is_dir($dir))) {
mkdir($dir);
chdir ($dir);
}
$contents = ftp_nlist($conn_id, ".");
foreach ($contents as $file) {
if ($file == '.' || $file == '..')
continue;
if (@ftp_chdir($conn_id, $file)) {
ftp_chdir ($conn_id, "..");
ftp_sync ($file);
} else {
ftp_get($conn_id, $file, $file, FTP_BINARY);
}
}
ftp_chdir ($conn_id, "..");
chdir ("..");
ftp_close($conn_id);
}
我还强烈建议采用某种形式的编码标准。 PEAR Coding Standards是一个很好的起点
答案 1 :(得分:0)
如果它没有返回到命令行那么它就处于某种无限循环中。