How to ensure that the zip file is completely downloaded.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to ensure that the zip file is completely downloaded.
Hi,
I am using unzip utility to unzip .zip file.
If unzip finds the file while it is downloading, it gives an error something like
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
Is there a way by which we can ensure that the .zip file has been properly downloaded before we give it to unzip utility.
Some downloaders will put a <filename>.zip.part file out there, along with just <filename>.zip. The .zip file will be zero bytes, while the .part file will contain the data. As soon as the download is complete, the .part file is moved to .zip, and removed, leaving you with one complete file.
Wget may act differently, as so some download utilities used through your web browser. You don't say what you're using, so it's hard to help.
If this is a program you're writing yourself, you should be able to easily monitor the download by looking for the thread in the process table, or checking the return status of the code....
I am using unzip utility to unzip my zip file.
I get the .zip file using secure ftp. And as soon as the file arrives, the utility tries to unzip it and fails giving the error mentioned below.
I am looking for a standard procedure (maybe) to ensure that the file is downloaded 100% and then go to the next line of code where the unzip utility is waiting to unzip it.
I tried,
cp /working_dir/file.zip to /tmp/file.zip
mv /tmp/file.zip to /working_dir/file.zip
but this didn't work.
Kind regards,
indiancosmonaut
Last edited by indiancosmonaut; 04-25-2008 at 02:00 PM.
Actually I run a script on my IBM AIX to unzip the file, which continuously checks for the zip file. Meanwhile at any point in time I ftp the file to the AIX box using secureshell (sftp). I am just transferring the file from my local machine to the UNIX box.
Actually I run a script on my IBM AIX to unzip the file, which continuously checks for the zip file. Meanwhile at any point in time I ftp the file to the AIX box using secureshell (sftp). I am just transferring the file from my local machine to the UNIX box.
What you're describing can't be done. It's like asking "How high is up?"; the file(s) you're transferring show up at "any point in time", and can be any size. Since you don't know when they'll show up, or how big they can be, there's no way to know what's going on.
There are some klunky ways of doing things, though. You might be able to transmit a second "confirmation" file, such as a <filename>.txt file, containing the file size of the .zip file. Your script on the 'receiving' box could look for that file, and if it finds it, begins processing. Further error checking could be done by opening the confirmation file, and comparing the size in it, to the actual size of the file, to make sure there were no transmission errors.
I think one more thing that could be done is that we check for the file size at regular intervals of time. After two consecutive checks, if the file size is unchanged then we can safely assume that the file is copied 100% and so we can go ahead with the unzipping.
I think one more thing that could be done is that we check for the file size at regular intervals of time. After two consecutive checks, if the file size is unchanged then we can recklessly assume that the file is copied 100% and so we can go ahead with the unzipping.
Kind regards,
indiancosmonaut
fixed.
Maybe another way would be to use lsof to check whether the file is opened by any programs. If it's not then it must be done downloading.
A simpler way may be to download it as another name, then rename it when it's complete (assuming you're using a script to download it here, otherwise you can do this by hand also. rename/mv takes (almost) no time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.