• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Downloading a file from an FTP

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys!

Im trying to open a connection with a server, and download a jar file and reconstruct it on the client system running the application. When the file downloads the jar is corrupt. Im assumed it was because I have downloaded in ascii format but Im using input and output streams for the process. Ive checked the jar file on the server and it is intact.

Any Ideas?

try{
URL fileurl = new URL("ftp://SERVERNAME/FILE.jar");
URLConnection urlC = fileurl.openConnection();
InputStream is = fileurl.openStream();
FileOutputStream fos= new FileOutputStream("C:\\SOMEDIR\\FILE.jar");

int count = 0;
int numb;
while( (numb=is.read())!=-1){
count++;
fos.write(numb);
}
is.close();
fos.close();
System.out.println(count +" byte(s) copied");
}catch(Exception ftpe){
System.out.println(ftpe);
}
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing your url to:
"ftp://SERVERNAME/FILE.jar;type=i"
That will tell the FTP client to handle the data as binary.
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks that semms to have made it work!
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't thank me. Thank the RFC1738 - Uniform Resource Locators document.
reply
    Bookmark Topic Watch Topic
  • New Topic