简体   繁体   中英

How to copy multiple files from server to local hard disk in one http request using C++?

How do you copy a group of files from server machine to local hard disk through a C++ web application in one request? This is kind of downloading bulk files to your local machine from a server. I guess in Java you could do this through ZipInputStream and GZipInputStream.

Is it possible to achieve this entirely through server side code? Or will it require a client running on the local machine to carry out the bulk copying of files?

Say you have a Java servlet / ISAPI extension that accepts requests of the form

http://server:port/fileserver?f=FILE1&f=FILE2&.....&f=FILEN

On receipt of such a request, the server side code can, using zlib, pack all the files into a zip file and send the zip file as the HTTP response setting the Content-Type, Content-Length, Last-Modified,etc.

Further Note: If you are using ISAPI on IIS6 and above, you can also add this content into the IIS's kernel mode response cache.

If the user if aware of this, and the files are not nessesary for website rendering, you can push them into an archive and have a link from your site (or do something like sourceforge, redirect to the archive and the browser simply downloads it. For archiving you can use zlib . Just send Content-type as gzip and push data (here from stdin)

int ret;

/* avoid end-of-line conversions */
SET_BINARY_MODE(stdin);
SET_BINARY_MODE(stdout);

ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK)
    zerr(ret);
return ret;

If you are trying to have the whole page (HTML, CSS, JS, IMG) sent as one, all of those files can be inserted into HTML, even images. (see this ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM