File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Corrupted Downloaded Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Corrupted Downloaded Files" Watch "Corrupted Downloaded Files" New topic

Corrupted Downloaded Files

Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
I use this method to download a file from a server to my local machine:

But it just work fine with some type of files and not with other (i get the .jpg's and the .html's OK, but I get the .ico, the .gif or the .swf corrupted ).
Do you now why?
Thanx in advance.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
As a guess, the ftp server may be using an ascii connection for some (or all) files. One way to test this is to use ftp manually, and set the connection to ascii by typing "type=ascii" before transferring. Compare the file you get this way with the file you get from your program - are the bytes identical? Are they corrupted exactly the same way? Now set type=binary and try again. Is the file OK this time? No corruption? If the answer to all these questions is yes, then your problem is indeed an ascii connection.
I'd think there should be a way to specify a binary transfer using the URL class - as I read the specs for URLs, it should be possible using something like
URL url = new URL("ftp://user;type=I");
However I can't get this to actually work - I keep getting FileNotFoundException for filename "file.ext;type=I". So I'm not sure if I'm doing something wrong, or Java just doesn't support this. Does anyone else know?
There is an Java FTP client library someone put together, available from GNU. You can always try using that, and/or study it for ideas. Good luck - and please let us know if you get a solution.

"I'm not back." - Bill Harding, Twister
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
My guess would be the semicolon should be a question mark in that url:
URL url = new URL("");
[ February 05, 2002: Message edited by: Steve Deadsea ]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Yeah, that does it, thanks. I should have thought to try that - I was foolishly believing that a document on URLs from might actually be relevant. Urg. Are there rules written down somewhere which are actually used, or does everyone make it up as they go? :roll:
I agree. Here's the link:
subject: Corrupted Downloaded Files
It's not a secret anymore!