• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem retrieving a zip file from FTP server using FTPClient commons-net-1.3.0.jar  RSS feed

 
priyanka pal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am trying to retrieve several zip files from FTP site using FTPClient . The retrieve process hangs when trying to get large files of 5MB.
the thread hangs without any errors or exceptions, although IO exceptions are handled in the code.
this has been happening repeatedly, since a week. Only on the application restart the process again starts adn then after sometime it again hangs.
There is no issue in retrieving smailler zip files.

Please help. Proghram attached below.


private boolean retrieveFromFTPSite(String ftpUrl,String username,String password,FTPClient ftp, String filePath) {


try {
TimeOutSetFactory timeOutSetFactory = new TimeOutSetFactory();
//Setting timeout to 20 seconds in TimeOutFactory class.
timeOutSetFactory.setTimeOut(20*1000);
ftp.setSocketFactory(timeOutSetFactory);
ftp.connect(ftpUrl);
ftp.login(username, password);
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024 * 1024 * 2);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println( "Timeout period"+ftp.getSoTimeout());
ftp.retrieveFile(filePath, bos); // thread hangs here
if (bos.toByteArray().length < 10) {
throw new IOException("Empty or corrupted file " + filePath);
}
bos.close();
return true;
} catch (IOException ioe) {

System.out.println("Error retrieving file. " + ioe.getMessage());
return false;
}
finally{
try {
ftp.logout();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags.
 
priyanka pal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really not indent your code?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!