Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Problems uploading file to FTP  RSS feed

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a zip file which work fine on my local file system. After I upload it to a FTP server, the file gets corrupted. It seems something gets appended to the file because the zip file is bigger after I've uploaded it.

When I try to unzip it after I've uploaded it says: error: invalid compressed data to inflate --> 77 extra bytes at beginning or within zipfile

I'm using the Jacarta Jacarta Commons Net FTP package to deal with the FTP server.

I can't figure this one out. Why does my code append data to the file when uploading it to the FTP?

Help!

Here's my code:

 
Bartender
Posts: 9521
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Egil Poma:

Why does my code append data to the file when uploading it to the FTP?



Because you are telling it to. This code:


always writes 8192 bytes to the output stream no matter how many bytes were read. You need to find out how many bytes were read in and only write that many out. Have a look at this example and let us know if it works or if you have any other questions.
 
Egil Poma
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, it was indeed the streams.

So I changed my upload code to this, and now it works:

// Upload file
InputStream in = new FileInputStream(file);
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
boolean stored = ftpClient.storeFile(fileName ,in);
in.close();

I had ro remove the completePendingCommand() statement to make it work as well.

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!