• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem with InputStream using org.apache.commons.net

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using org.apache.commons.net to ftp to the remote machine.I am successful in getting the directory and file listing in ftp server.

But when I try to read the properties of a word doucument there is a problem.

The code is given below:

public class Ftp {



public static void main(String[] args) {
try {
FTPClient ftp=new FTPClient();

String server = "172.16.56.216";

String directory = "/main/book/dam";

ftp.connect(server);
ftp.login(args[0], args[1]);
System.out.println("Connected to " + server + ".");

FTPFile[] files = ftp.listFiles(directory);

for (int i = 0; i < files.length; i++) {
checkDiectory(files[i], directory,ftp);
System.out.print(ftp.getReplyString());
}
System.out.print(ftp.getReplyString());

ftp.disconnect();

} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Main Error");
e.printStackTrace();
}

}

/**
* @param file
* @param directory
* @param ftp
*/
public static void checkDiectory(FTPFile file, String directory, FTPClient ftp) {
// TODO Auto-generated method stub
ArrayList resultSet=new ArrayList();

if (file.isDirectory()) {

String dirCont = directory + "/" + file.getName();
System.out.println("Directory" + dirCont);
FTPFile[] fileIn = new FTPFile[512];
try {
fileIn = ftp.listFiles(dirCont);
for (int i = 0; i < fileIn.length; i++) {
checkDiectory(fileIn[i], dirCont,ftp);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

} else if (file.isFile()) {
String dirCont =new String();
dirCont = directory + "/" + file.getName();
System.out.println("File" + dirCont);

try {
/*****The problem is here****/
InputStreamin=ftp.retrieveFileStream(dirCont);
/*****************************/


System.out.println("Stream"+in);
//ExtractionUtil extUtil=new ExtractionUtil();
// String content=new String();
//content=extUtil.getMSDocContent(in);
//System.out.println("Content"+content);
// in.close();
WordDocument word = new WordDocument(dirCont);
word.getDocumentProperties(in);

//word.getDocumentContent(in);
resultSet.add(word);
in.close();

Iterator it=resultSet.iterator();

Object obj=null;
while(it.hasNext()){
obj = it.next();
if (obj instanceof WordDocument) {
System.out.println("DOC");
Document wor = (Document) obj;
System.out.println("Doc Author : " + wor.getDocumentProperties().getAuthor());
//System.out.println("Doc Content:"+wor.getDocumentContent());
}

}
System.out.print(ftp.getReplyString());
//System.out.println("Author"+properties.getAuthor());
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("ERROR");
e.printStackTrace();


}


}

}

}
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic