• Post Reply Bookmark Topic Watch Topic
  • New Topic

probem with FTPing the file using commons-net  RSS feed

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

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;
try
{
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()");

/*if(!ftp.completePendingCommand())
{
throw new Exception("completePendingCommand() returned false");
}*/

if (!FTPReply.isPositiveCompletion( ftp.getReplyCode() ))
{
System.out.println("complete");
}
else
{
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());
e.printStackTrace();
}
finally{
// close input stream
if(fos != null)
fos.close();
System.out.println("FTP end");
}
}

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