Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:34:17+00:00 2026-06-05T19:34:17+00:00

In my application I upload a byte[] (serialized Object) to my FTP server, which

  • 0

In my application I upload a byte[] (serialized Object) to my FTP server, which is working perfectly. However when I try to download it only the first part (like 3000 bytes) of the array are correct, the rest is filled with zeros.

I can’t seem to figure out what is wrong, any help would be appreciated.
I am using the package
org.apache.commons.net.*

public static byte[] downloadBoard( String host, int port, String usr, String pwd) throws IOException {
  FTPClient ftpClient = new FTPClient();
  byte[] buf = new byte[20000];

  try {
    ftpClient.connect( host, port );
    ftpClient.login( usr, pwd );

    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    InputStream is = ftpClient.retrieveFileStream("asdf.board");
    is.read(buf);
    is.close();

    ftpClient.completePendingCommand();
    ftpClient.logout();
  } finally {
    ftpClient.disconnect();
  }
  return buf;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:34:18+00:00Added an answer on June 5, 2026 at 7:34 pm

    is.read() may not return the full content. You’ll need to put read() into a loop similar to this:

    int pos = 0;
    while (true) {
      int count = is.read(buf, pos, buf.length - pos);
      if (count <= 0) {
        break;
      }
      pos += count;
    }
    

    P.S.:

    If you know the size of the file, you can use a DataInputStream to read the buffer without a loop:

    byte[] buf = new byte[exactFileSize];
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(buf);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got a server host that only let me upload files through ftp (with
I am able to have my application upload files via FTP using the FTPClient
I'm supposed to use Amazon s3 in my application to upload/download files. Can anyone
I am working on an application which will store some entities which have name,
I am creating an application to upload data to a server. The data will
I'd built an WSSv3 application which upload files in small chunks; when every data
I've been writing a little application that will let people upload & download files
For an application I'm working on, I need to allow the user to upload
I'm creating a simple drag-file-and-upload-automatically-to-ftp windows application and I'm using the MSDN code to
I'm trying to upload a file to an FTP server using code based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.