• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Corrupted Downloaded Files

 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic