How to list all the available shared folders under a specific IP Address?
Mock code:
IP ip = new IP("10.0.0.9");
for(File share : ip.getSharedFolders){
System.out.println(share.getName());
}
Is there a way in which this can be accomplished?
I want to make something similar to windows network explorer and I need to get all the shared folders under a specific IP so I can ggenerate a tree.
With the first level shared folders I can easely get the lower levels like this
for(File f : new File("//10.0.0.9/d").listFiles()){
System.out.println(f.getName());
You can get the list of shares using the The Java CIFS Client Library and in particular the SmbFile.list method. Here is a small illustration of how to use this API:
SmbFile server = new SmbFile("smb://server/");
String[] shares = server.list();
Java from out of the box does not support what you are trying to do.
You need to use libraries such as JCIFS to do this.
One easy/cludgy way out though would be to make sure that you have a drive mapping ( if windows or nfs/smb mount for other OSs) to the location and then treat it as a local file - using java.io APIs.
If the files are accessible through the server IP address (network wise and permission wise) then sure you can list them all recursively by doing the following:
Get the remote folder name. Example "//10.0.0.9/folder"
Iterate through that folder just as you would do to list files in a local directory (see this link to know more about listing local files in a local directory
Related
I want to access a file server that is not present in my network, but I have credentials of other domain that can be used to access the file.
How do I gain access to the file in share?
Is it possible to gain access to the file using a java program?
Operating System is Windows. I want to read the contents from .txt and .csv files present in the share and display it on a web page.
I used jcifs library to solve this. It works great.
You can use ftp protocol.
And also can make a map drive from share folder on your system. It's a simple solution.
I need to connect to a windows shared drive so I can make a directory and then some files in that directory. I am not sure how I would go about this. Can you use any built in classes for java?
If you map the drive onto your machine you should be able to access the drive with the normal filepath "(Drive Letter):/"
Depending on your network configuration you might also be able to use the filepath "\(Server name)\"
FTP client class is not connecting
further to this link i just want to know to upload a file in specific directory location for example there is a cross reference in IP and then further a library in cross reference then how would i upload file in library or in precise how would i get connected to ip/cross reference/library for location where i need to upload a file. here i want to mention that i successfully get connected to IP till now.
The constructor of FTPHTTPClient doesn't appear to take a path in the constructor, its just the hostname/ip. Also, most FTP clients use / and not \ as the path separator.
The JavaDoc for FTPClient shows there is a method changeWorkingDirectory(String pathname), which I am guessing is what you want to do.
I need to create a list of links on my JSP, related to some files that are in a specific folder (with html extension), on a Unix server.
My questions are:
How do I "connect" to the Unix server? My JSP will be stored on the same server that I need to search into.
What method I should use to search through my specific folder?
You can use the File.listFiles(...) method (on any OS/filesystem actually). Be aware that there might be limitations if the uid for webserver has no access to the folder/files or is eg. in a chroot'ed environment on the UNIX box.
The following code snippet
File[] files = new File( "/your/folder" ).listFiles( "*.html" );
should give you a File[] array with the files satisfying the .html condition in /your/folder.
Cheers,
You could do this in several ways.
If the share on the server is local or locally mounted already, then you can use Anders R.Bystrups answer.
If it is not, then you need some method of connecting to the server.
If it is a shared resource (a shared folder, for example), then you can access it with //server/share/file).
If the server is running FTP or SFTP, then you can use the relevant service to retrieve the list of files.
Finally, the server could run a web service (which you would have to write) which could expose the list of files it has.
I am developing a java application which scans all the systems over the local area network, and gives a list of systems having some files shared, thus making port 445 open. I can check whether port 445 is open or not, but how can I get the list of files or directories shared by the target system, given that I know the ip address of the target system. Any help in this regard will be much appreciated.
This program is similar to another program 'netscan' (windows).
jCIFS is a library to access SMB shares directly from Java. Read more detailed documentation here