This article mainly introduces how to use php programs to download remote network files to your host (server and virtual host). of course, the source code of asp and asp.net is also provided for your reference.
This article mainly introduces how to use php programs to download remote network files to your host (server and virtual host). of course, the source code of asp and asp.net is also provided for your reference.
I recently asked Lc to download the touching inspirational TV series "a boat in Wang Yang". for the convenience of sharing, I provided a Godaddy free FTP.
Considering the stability and uniqueness, I want to re-open a free godaddy space, but now I have uploaded two sets, a total of over 400 MB. what should I do?
As a result, I think of a php file used for space transfer. it can download a remote network file to the server, that is, transfer the file to a new server as long as it is a downloadable url.
If you don't talk much about it, you can directly download the remote network file to the php source code of the server (the test passes and is very powerful ).
<? Php // Maximum execution time in seconds Set_time_limit (24*60*60 ); If (! Isset ($ _ POST ['submit ']) die (); // Folder to save downloaded 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, you also need to display the source code of the asp version (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" %>Source code for asp.net (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 the local path and file name String fileName = "c: \ xxx.rar "; // Instantiate a WebClient WebClient client = new WebClient (); // Call the WebClient's DownloadFile method Client. DownloadFile (siteURL, fileName ); } } |
Note:
1. related directories may need to be created. for details, see the source code, such as temp/and down /.
2. the source code of the php version supports custom URLs, but the asp and asp.net versions do not provide custom URLs.
3. when copying large files, it is estimated that the support in China is poor, because the program timeout time is considered, but the support abroad is good.
For example, it takes 28 seconds for Blinux to transfer a file of nearly MB to another server. this is unimaginable in China.
Finally, I hope you can give feedback on the use results.