aspose file tools*
The moose likes Java in General and the fly likes Save file to remote computer on same LAN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Save file to remote computer on same LAN" Watch "Save file to remote computer on same LAN" New topic
Author

Save file to remote computer on same LAN

Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
We have a hardware contractor who needs to transfer a file (actually I think that the data are in memory) between a specialty camera with build in LINUX to a remote computer on the same LAN (just a router between them). I tried a test between two of my LINUX machines but it fails with a "fine not found" error (not the SecurityException error). I'm logged into both computers as programmer. Programmer on both machines is in the same group. I've tried to send the data to ~/temp and to ~.Public. Public is read write to anyone. I've tried a few ways of formatting the path name. Here's the offending code (which is in a try-catch):



Any thoughts?
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Can you copy a file manually from the source to the target location, using the same user account as the Java program? I.e. "cp copiedfile.txt //192.168.1.106/home/programmer/Public/"
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Windows share support works a lot better under Windows. Perhaps you can try JCIFS instead.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
I can't cp from terminal but I can do
ssh programmer@192.168.1.106


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

Nate Lockwood wrote:I can't cp from terminal but I can do
ssh programmer@192.168.1.106


If you can't do the command from the command line -- then chances are a java program trying to do the same thing won't work either.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
Henry Wong wrote:
Nate Lockwood wrote:I can't cp from terminal but I can do
ssh programmer@192.168.1.106


If you can't do the command from the command line -- then chances are a java program trying to do the same thing won't work either.

Henry


Yeah, I suspect it's a security problem and of course I tried the code first! I can rsync from terminal. There must be some way.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Nate Lockwood wrote: I tried a test between two of my LINUX machines but it fails with a "fine not found" error (not the SecurityException error).

Just to clarify, the SecutrityException is thrown by the security manager to indicate a security violation (from its Javadoc). Security manager does not deal with file system permissons.

Lack of filesystem permissions generally leads to IOException or some of its subclass, a FileNotFoundException may pretty well indicate a permission problem.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

I wouldn't expect Java to recognize a file name of the form //host/path. Java's File class and file I/O classes deal only with files on the local file system (including those that are mounted from a remote host via NFS, Samba, etc., to appear as part of the local FS). So if ls //host/path doesn't work, then Java's file I/O won't either.

You'll have to either execute an rsync or scp ftp or some such command as an external process, or get a thirdparty Java library that speaks one of those protocols.
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
Thanks, all. I'm still at home and my caffeine rush is just kicking in... The easiest solution might be to use NFS to map (mount) the folder on the remote computer (server) on the local machine (client). Then the mounted filesystem would appear to be local to the Java File class? I'm guessing that nfs is part of LINUX so additional software will not be required.

I like this. One just needs to attempt the mount at boot without hanging if the other machine is not connected or turned on.

Will a LINUX machine be able to mount a Windows filesystem?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Nate Lockwood wrote:Thanks, all. I'm still at home and my caffeine rush is just kicking in... The easiest solution might be to use NFS to map (mount) the folder on the remote computer (server) on the local machine (client). Then the mounted filesystem would appear to be local to the Java File class?


Yes, it would.

I'm guessing that nfs is part of LINUX so additional software will not be required.


Yeah, it should be a standard part of any Linux distro, although it may or may not have been installed when the box in question was imaged. I don't know if NFS is still widely used, or if there's a preferred replacement. You might want to do a big of googling for "linux remote file system" or something just in case. (It's not that I don't think it's used, just that I haven't done any Linux-Linux drive sharing for a while, so I don't know.)

Will a LINUX machine be able to mount a Windows filesystem?


As far as I know, Samba is the de facto standard tool for that. I've used it a handful of times, with mixed luck. In my experience, it's kind of finicky. There may or may not be NFS implementations for Windows.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Nate Lockwood wrote:Will a LINUX machine be able to mount a Windows filesystem?

Yes it would, using the smbfs file system. You need to have at least the client parts of Samba installed. I've managed to do that on my old RedHat machine 10 years ago, so it should definitely work these days.

But as I already mentioned, a library like JCIFS allows you to access a Windows share without having to mount it first.

Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

You mentioned that SCP works, so instead of creating a share, you could also use JSch to SCP the file to the remote location. A code example can be found here.
Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
I did get it working but I followed a Ubuntu "how to" that I think was designed to mount users to a remote machine. When I unscrambled that and used the correct path it worked transparently from my little test app.

Thanks, all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save file to remote computer on same LAN