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;
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.
精彩评论