• Post Reply Bookmark Topic Watch Topic
  • New Topic

probem with FTPing the file using commons-net  RSS feed

Bharat Athreya
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When i'm trying to Ftp the file from the server, the code hangs when it encounters boolean commandOK=ftp.completePendingCommand(); statement.

The file size is just 2KB...

Here is the Code Snippet

private void doFtpOnly(FTPClient ftp, FTPFile serverFile) throws Exception
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
int count;
byte data[] = new byte[1024];
FileOutputStream fos = null;
Exception exception = null;
System.out.println("FTP Download: " + serverFile.getName() +
" with timestamp " + df.format(serverFile.getTimestamp().getTime()));

fos = new FileOutputStream("C:/ftp" +File.separator +serverFile.getName());

// stream the ftp contents into an inputstream
// this always returns false
if(!ftp.retrieveFile(serverFile.getName(), fos))
// throw new Exception("false return from ftp.retrieveFile()");
System.out.println("false return from ftp.retrieveFile()");
/* this command freezes every time when running on Windows */
System.out.println("to ftp.completePendingCommand()");

throw new Exception("completePendingCommand() returned false");

if (!FTPReply.isPositiveCompletion( ftp.getReplyCode() ))
System.out.println("In complete");
boolean commandOK=ftp.completePendingCommand();
System.out.println("pending cmd complete-status egatedev:" +commandOK);

System.out.println("did ftp.completePendingCommand()");

}catch(Exception e)
System.out.println("doFtpOnly : " + e.getMessage());
// close input stream
if(fos != null)
System.out.println("FTP end");

Please help me out to
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!