• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problems uploading file to FTP

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic