[英]download file from remote server and delete after complete downloading
i try to download file from remote server by use wget. 我尝试使用wget从远程服务器下载文件。 and i want to delete remote server file after complete downloading.
我想在完全下载后删除远程服务器文件。
here is my code for download file. 这是我的下载文件代码。
<?php
function remoteFileExists($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
$result = curl_exec($curl);
$ret = false;
if ($result !== false) {
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($statusCode == 200) {
$ret = true;
}
}
curl_close($curl);
return $ret;
}
$exists = remoteFileExists('http://192.168.X.X/123/123.rar');
if ($exists) {
shell_exec('wget http://192.168.X.X/123/123.rar');
echo"file downloaded";
} else {
echo 'file does not exist';
}
?>
but this is also give error like below: 但这也给如下错误:
--2014-01-28 11:17:38-- http://192.168.X.X/123/123.rar
Connecting to 192.168.X.X:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 345 [text/plain]
123.rar: Permission denied
Cannot write to `123.rar' (Permission denied).
Cannot write to '123.rar' (Permission denied).
means that your PHP (mod_php running as Apache user?) doesn't have permissions to write the file to your local server. chmod 777
) a directory where writing is permitted. chmod 777
)允许写入的目录。 Let's assume your Apache can save to /tmp
假设您的Apache可以保存到
/tmp
$local_dir = '/tmp';
shell_exec("wget -P $local_dir http://192.168.X.X/123/123.rar");
ssh remote-server "rm /path/to/123/123.rar"
if you have ssh
access (but then you would just scp
the file in the first place, wouldn't you?). ssh remote-server "rm /path/to/123/123.rar"
如果你有ssh
访问(但你只想scp
摆在首位的文件,不是吗?) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.