This article mainly describes how to use the PHP program to download the remote network files to their own host (server, virtual Host), of course, also provides the ASP, asp.net source for reference.
Recently let Lc. Download "A boat in the ocean" This touching inspirational TV series, in order to share the convenience, so I provide a GoDaddy free FTP.
Considering the stability and specificity, I would like to reopen a GoDaddy free space, but this time has been uploaded two episodes, a total of more than 400 trillion. What do we do?
So I think of the previous transfer space used in a PHP file, he can download the remote network files to the server, that is, as long as the URL can be downloaded, you can transfer to the new server.
Nonsense not much said, directly to the remote network file download to the server PHP source code (test passed, very good very strong).
<form method= "POST" >
<input name= "url" size= "a"/>
<input name= "Submit" type= "Submit"/>
</form>
< PHP
Maximum execution time in seconds
Set_time_limit (24 * 60 * 60);
if (!isset ($_post[' submit ')) Die ();
Folder to save downloaded the files to. Must end with slash
$destination _folder = ' temp/';
$url = $_post[' url '];
$newfname = $destination _folder. BaseName ($url);
$file = fopen ($url, "RB");
if ($file) {
$NEWF = fopen ($newfname, "WB");
if ($NEWF)
while (!feof ($file)) {
Fwrite ($NEWF, Fread ($file, 1024 * 8), 1024 * 8);
}
}
if ($file) {
Fclose ($file);
}
if ($NEWF) {
Fclose ($NEWF);
}
?>
Of course also need to show the ASP version of the source code (not tested)
<%
function Downfilea (D_target, S_target)
On Error Resume Next
Dim myhttp, Objstream
Set myhttp = Server.CreateObject ("MSXML2. XMLHTTP ")
Myhttp.open "Get", D_target, False
Myhttp.send ()
Set objstream = Server.CreateObject ("ADODB.stream")
Objstream. Type = 1
Objstream. Mode = 3
Objstream. Open
Objstream. Write Myhttp.responsebody
Objstream. SaveToFile S_target, 2
If Err.Number <> 0 then err. Clear
End Function
Downfilea "Http://www.abc.com/xxx.rar", Server.MapPath ("Down/xxx.rar")
Response.Write "OK"
%>
There are asp.net version of the source code (not tested)
Using System;
Using System.Net;
Using System.IO;
Class DownloadFile;
{
static void Main (string[] args)
{
Your remote file.
String siteurl= "Http://www.abc.com/xxx.rar";
Download to local path and filename
String Filename= "C:\\xxx.rar";
Instantiate a WebClient
WebClient client=new WebClient ();
Call the WebClient DownloadFile method
Client. DownloadFile (Siteurl,filename);
}
}
Note:
1. The relevant catalogue may need to be established, please see the source code. Like temp/, down/.
2. The PHP version of the source code is to support the custom URL, but the ASP, asp.net version does not provide customization.
3. At the time of copying large documents, domestic estimates were poorly supported. Because of the timeout of the program, it is very good to support abroad.
For example, it takes 28 seconds for Blinux to transfer a file near 300M to another server. This is unthinkable at home.
Finally, I hope everyone feedback under the use of effect.