Switch to full style
What's behind JSP & Servlets
Post a reply

Accessing files in remote server (unix/windows) using JSP

Tue Apr 05, 2011 8:17 am

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 :banghead: for this from long time, but no success :cray:

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. :gOOd:

Regards,
Kishore



Re: Accessing files in remote server (unix/windows) using JSP

Tue Apr 05, 2011 10:02 am

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;
    }
}


 


Re: Accessing files in remote server (unix/windows) using JSP

Tue Apr 05, 2011 10:05 am

HI,

:clapping: :clapping: :clapping:

Thanks for the reply :gOOd:

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. :cray:

Kindly suggest.

Re: Accessing files in remote server (unix/windows) using JSP

Wed Apr 06, 2011 9:35 am

why don't you use FTP.
Java FTP

Post a reply
  Related Posts  to : Accessing files in remote server (unix/windows) using JSP
 Sql server or windows server question?     -  
 FTP WITH WINDOWS SERVER 2003     -  
 Fax Services Access in Windows Server 2003     -  
 copy files from applet server to client     -  
 Get disk free space for Unix-Linux in php     -  
 php Accessing a Property from Within a Method     -  
 Dynamically Setting and Accessing Variables     -  
 update an xml file with jaxb and accessing to its elements     -  
 Get Remote port     -  
 get Remote host     -