aspose file tools*
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
Author

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
Wanderer
Sheriff

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 asswd@server.com/dir/file.ext;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("ftp://user:passwd@server.com/dir/file.ext?type=I");
[ February 05, 2002: Message edited by: Steve Deadsea ]
Jim Yingst
Wanderer
Sheriff

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 w3.org 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:
 
jQuery in Action, 2nd edition
 
subject: Corrupted Downloaded Files