title: How to measure upload/ download speed with Apache FTPClient
body: <p>I am using Apache FTPClient to download / upload files between android device and some FTP server.
  I would like to measure the download and upload speeds in Mbps / KBps.</p>
  
  <p>for upload, my code looks something like this:</p>
  
  <pre><code>// myFile is a path for local file inside my android device.
  InputStream inputStream = new FileInputStream(myFile);
  OutputStream outputStream = ftpclient.storeFileStream(remoteFile);
  
  byte[] bytesIn = new byte[4096];
  int read = 0;
  
  while((read = inputStream.read(bytesIn)) != -1) {
      outputStream.write(bytesIn, 0, read);
  }
  
  inputStream.close();
  outputStream.close();
  </code></pre>
  
  <p>It is important for me to know two things:</p>
  
  <ol>
  <li>For download, what I did was to sum up the bytes that I have been read inside the while loop (using inputStream.read(serverFile) return value)
  is it ok ? will it reflect the download speed?</li>
  <li>For upload, how do I measure correctly the upload speed for a file ? how can it be done by this FTP client ?
  for what I know, outputStream.write() doesn't return useful value..
  my thought is to check after every iteration (writing) what is the updated size of the file in the FTP server but I don't know if this is the right / simplest way. and also, how to implement it with this FTP client.</li>
  </ol>