Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with InputStream using org.apache.commons.net  RSS feed

 
samind crasta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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();


}


}

}

}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!