开发者

Checing if FTPClient download has received all bytes

I download an image file from an FTP Server using FTPClient. My look like this:

public class FtpDownloadDemo
{
 public static void main(Strin开发者_开发技巧g[] args)
 {
  FTPClient client = new FTPClient();
  FileOutputStream fos = null;

  try
  {
    client.connect("ftp.domain.com");
    client.login("user", "pass");

    //
    // The remote filename to be downloaded.
    //
    String filename = "side.jpg";
    fos = new FileOutputStream(filename);

    //
    // Download file from FTP server
    //
    client.retrieveFile("/" + filename, fos);
  }
  catch (IOException e)
  {
    e.printStackTrace();
  }
  finally
  {
    try
    {
      if (fos != null)
      {
        fos.close();
      }
      client.disconnect();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }

 }
}

When the file is downloaded the output looks distorted as shown below;

Checing if FTPClient download has received all bytes

Is there a way to check if all the bytes has been received else wait till all is received?


I strongly suspect that the real problem is that the transfer is done in ASCII, rather than binary, mode.

Try calling client.setFileType(FTP.BINARY_FILE_TYPE); before initiating the transfer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜