Two Laptop Bag
The moose likes Sockets and Internet Protocols and the fly likes probem with FTPing the file using commons-net Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "probem with FTPing the file using commons-net" Watch "probem with FTPing the file using commons-net" New topic
Author

probem with FTPing the file using commons-net

Bharat Athreya
Greenhorn

Joined: Mar 09, 2006
Posts: 10
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


Bharat Athreya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: probem with FTPing the file using commons-net
 
Similar Threads
Jar Extraction Problem
Reading log files from various unix servers through Java program on windows
Writing a FileOutputStream into a File
Problem with InputStream using org.apache.commons.net
problem retrieving a zip file from FTP server using org.apache.commons.net.ftp.