Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get free Disk Space on remote machine  RSS feed

 
nish projects
Greenhorn
Posts: 5
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just want to know if we can get to know how much free space is left on the remote machine. For example if i have a IP of the machine say xxx.xxx.xxx.xxx, can i get to know what is the free space left on this machine?

Thanks in advance.

Nish
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, how would you connect to that IP? Is it a mapped share, or via SSH/FTP/??? You can use the getFreeSpace() method on a java.io.File instance as of Java 6.
 
nish projects
Greenhorn
Posts: 5
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be using the simple java IO calls through a windows based system. Would the getfreespace method works for the network drives too?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nish projects wrote:I just want to know if we can get to know how much free space is left on the remote machine


You can if there is some service running on that machine providing that information (such as SNMP, WMI, or some custom service that you create), or if you can remotely log into that machine (for example, using the ssh protocol, which is provided by JSch and probably others) and then execute a command there (such as df it it's a Linux box).
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nish projects wrote:I would be using the simple java IO calls through a windows based system. Would the getfreespace method works for the network drives too?


Only if they're mapped to appear as local drives. The java.io classes that deal with files only work on the local file system.
 
nish projects
Greenhorn
Posts: 5
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff,

All the system in the network are windows based..
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nish projects wrote:Hi Jeff,

All the system in the network are windows based..


Then probably ssh + df is not an option for you, although I assume Windows has an equivalent command. (You'd still need an ssh server running though too.)
 
nish projects
Greenhorn
Posts: 5
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
nish projects wrote:Hi Jeff,

All the system in the network are windows based..


Then probably ssh + df is not an option for you, although I assume Windows has an equivalent command. (You'd still need an ssh server running though too.)


Ok. Is there any other way to do it. My requirement is to check for the disk space on the remote machine which is windows based and for which the IP has been provided, provided there will be no ssh installed or drive mapping.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nish projects wrote:
Ok. Is there any other way to do it.


You've been given several examples. You need to do some research and see if any of them are appropriate. If not, and you're still stuck, you need to come back here and explain why they're not appropriate. You haven't given enough details about your requirements, constraints, and use cases for anybody to be able to offer anything more specific.

My requirement is to check for the disk space on the remote machine which is windows based and for which the IP has been provided,


Yes, you have stated that already.

provided there will be no ssh installed or drive mapping.


Okay, then, as you already know from what's been said here, you can't use ssh and you can't use Java's core file I/O facilities. Do some research on SNMP and WMI, or google for java remote windows drive access or something.

You may also look into JCIF. I think that lets you access a remote Windows drive without having to map it, although I assume it has to still be shared on its own local host.

In the end, there must be some service running on the remote host that lets you access its drives. It's impossible to do it otherwise.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:The java.io classes that deal with files only work on the local file system.

Not completely true. java.io.File can handle network shares as long as a) the local system is Windows, b) the share is a Windows share, and c) the user running the Java code has access to the share.
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Jeff Verdegan wrote:The java.io classes that deal with files only work on the local file system.

Not completely true. java.io.File can handle network shares as long as a) the local system is Windows, b) the share is a Windows share, and c) the user running the Java code has access to the share.

Local system doesn't need to be Windows. I've used File on a UNIX systems with mount point (using Sharity Light) to a Windows share.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Jeff Verdegan wrote:The java.io classes that deal with files only work on the local file system.

Not completely true. java.io.File can handle network shares as long as a) the local system is Windows, b) the share is a Windows share, and c) the user running the Java code has access to the share.


Are you saying java.io.File can parse UNC paths, e.g. \\10.0.0.1\some_share, as opposed to having to explicitly map it through Windows first? If so, that must be relatively new (like since 1.5 or something). I know it didn't used to be able to do that.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Koen Aerts wrote:
Rob Spoor wrote:
Jeff Verdegan wrote:The java.io classes that deal with files only work on the local file system.

Not completely true. java.io.File can handle network shares as long as a) the local system is Windows, b) the share is a Windows share, and c) the user running the Java code has access to the share.

Local system doesn't need to be Windows. I've used File on a UNIX systems with mount point (using Sharity Light) to a Windows share.


Yeah, but is is mounted so that it's visible as a local file system, such as /mnt/my_windows_drive? Or were you specifying the remote host in the File object?
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Koen Aerts wrote:
Rob Spoor wrote:
Jeff Verdegan wrote:The java.io classes that deal with files only work on the local file system.

Not completely true. java.io.File can handle network shares as long as a) the local system is Windows, b) the share is a Windows share, and c) the user running the Java code has access to the share.

Local system doesn't need to be Windows. I've used File on a UNIX systems with mount point (using Sharity Light) to a Windows share.

Yeah, but is is mounted so that it's visible as a local file system, such as /mnt/my_windows_drive? Or were you specifying the remote host in the File object?

The share would have to be mounted so that it looks like it's local. But - and I might be wrong here - it is the share that determines what you can do with java.io.File. For instance in my case (local UNIX system mounted to remote share on Windows) I could not rename a file from one letter case to another (i.e. myfile.txt to MYFILE.TXT) because according to the share (Windows) you cannot rename a file to the same name. However in a pure UNIX filesystem that would have worked because it's case sensitive (unlike Windows by default isn't, although you can change that).
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Koen Aerts wrote:
The share would have to be mounted so that it looks like it's local.


Okay. That was the point I was making earlier. Namely, that, as far as I know, File, FileReader/Writer, etc., don't let you specify a file in any sort of host + path format.

But - and I might be wrong here - it is the share that determines what you can do with java.io.File.


Yeah, I would expect that to be the case.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Rob Spoor wrote:
Jeff Verdegan wrote:The java.io classes that deal with files only work on the local file system.

Not completely true. java.io.File can handle network shares as long as a) the local system is Windows, b) the share is a Windows share, and c) the user running the Java code has access to the share.


Are you saying java.io.File can parse UNC paths, e.g. \\10.0.0.1\some_share, as opposed to having to explicitly map it through Windows first? If so, that must be relatively new (like since 1.5 or something). I know it didn't used to be able to do that.

I don't know since when it's possible, but now it certainly is. Of course you need to escape the \\ to \\\\, but it still works.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Jeff Verdegan wrote:
Rob Spoor wrote:
Jeff Verdegan wrote:The java.io classes that deal with files only work on the local file system.

Not completely true. java.io.File can handle network shares as long as a) the local system is Windows, b) the share is a Windows share, and c) the user running the Java code has access to the share.


Are you saying java.io.File can parse UNC paths, e.g. \\10.0.0.1\some_share, as opposed to having to explicitly map it through Windows first? If so, that must be relatively new (like since 1.5 or something). I know it didn't used to be able to do that.

I don't know since when it's possible, but now it certainly is. Of course you need to escape the \\ to \\\\, but it still works.


Good to know. Thanks.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!