• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

probem with FTPing the file using commons-net

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic