Question subject: Accessing files in remote server (unix/windows) using JSP
Posted: Tue Apr 05, 2011 8:17 am
Joined: Tue Apr 05, 2011 8:04 am Posts: 2 Has thanked: 0 time Have thanks: 0 time
Hi All,
Good morning to all.
I am doing a project for monitoring OS of different system (Unix and Windows) using JSP.
I want to know if you can help me in writing code for accessing file in remote server in JSP. I am struggling hard for this from long time, but no success
Also can i know if i can execute OS commands remotely (Unix/Windows where jdk is only installed) from JSP server ( where tomcat and jsp application is running)
Thanks in advance.
Regards, Kishore
msi_333
Question subject: Re: Accessing files in remote server (unix/windows) using JSP
Posted: Tue Apr 05, 2011 10:02 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
code help .
Code:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package mailtest.customgui;
import java.io.*; import java.lang.String; import java.io.File; import java.util.*; import java.util.List; import java.lang.*; public class RemoteFileTest {
private File fileObj; private Map mapfiles;
public RemoteFileTest(){ fileObj = new File("\\\\IPorComputerName\\path");
mapfiles = new HashMap(); mapfiles=printFileInfo(fileObj, mapfiles); Iterator filesIterator = mapfiles.keySet().iterator(); while (filesIterator.hasNext()){ String filePath =(String) filesIterator.next(); String fileName =(String) mapfiles.get(filePath); System.out.println("File name is "+ fileName); System.out.println("File path is "+ filePath); } }
public static void main(String args[]){ new RemoteFileTest(); }
/* * * Print the content of path , and return a map * of all files in it .with path and name. */ public Map printFileInfo(File fileObj, Map filesMap){ File[] files = fileObj.listFiles(); // If the current is directory. if (fileObj.isDirectory()){ // list for files inside the this directory. for (int i = 0; i < files.length; i++){ printFileInfo(files[i], filesMap); } } else { // get the information of fileObj , path is key,name is value to map. String path = fileObj.getPath(); String name = fileObj.getName(); filesMap.put(path, name); } return filesMap; } }
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
kishore007
Question subject: Re: Accessing files in remote server (unix/windows) using JSP
Posted: Tue Apr 05, 2011 10:05 am
Joined: Tue Apr 05, 2011 8:04 am Posts: 2 Has thanked: 0 time Have thanks: 0 time
HI,
Thanks for the reply
But What if i want to read the file without a share.. since i have to read files from UNIX, using samba is restricted in some of servers, especially production servers.
Kindly suggest.
msi_333
Question subject: Re: Accessing files in remote server (unix/windows) using JSP
Posted: Wed Apr 06, 2011 9:35 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time