Remote file transfer between windows system using Java - java

How to do remote file transfer between windows system using Java? In more detail, these windows systems are in same domain. I want Java API, which can transfer files (ASCII and Binary) between windows system by using assigned username, password, domain name and source and destination file location.

Use Sockets to connect (previous configuration by IP) to a SocketServer and transfer the files.

I've never done this, but I'd say you'll need to use the native Windows API to achieve this.
You could do it with JNI and C#. C# has File.Copy (see example here) that makes use of native CopyFile function.
Alternatively, take a look at this question on SO.
Hope this gives you some leads.

Related

copy files to a machine in local network in java with authentification

I've used Commons IO to write a program that copy files and other things. But I want to copy a file to a local ip address \\10.x.x.x, but the user doesn't have rights to do the copy, so I need to put an ID and password to access it. However I cannot find a way I can do that.
To move file I use :
FileUtils.moveFileToDirectory(fichier, destDir,true);
But my directory is something like \\10.x.x.x\files and only a few users can write in that directory so I have an ID & password that let you move files there. I want that even if the users don't have rights to move files to that directory my program can do it.
It is not really the way Windows security works. If you really want to do it that way, you will have to use Java Native Interface or Java Native Access, and manage to call the WNetAddConnection function from Mpr.dll (and do not forget to call WNetCancelConnection when done).
But you would have to store a password in your program, which is poor security practice.
The standard way to do that would be to start a service that would run under a user that has access to the desired directory, and have your program to communicate with it using whatever you want, the simplest way being probably TCP/IP. But unless you have special requirement for that I would not recommend to use Jave for those kinds of program.
A more Java alternative would be to start a Tomcat service on server machine running under a user having access to the directory. That way you just have to develop a standard Java Web Application able to upload files that would save the files to the proper directory. But it would be a traditionnal and portable Java application with no need for JNI nor JNA.
If cannot use a Tomcat and do not want to invest to much on it, you could split the program in pieces :
one client program that copies files on a directory (on server machine) with File creation rights for everybody - can decays to the copy utility if nothing more has to be done or can easily written in Java
one server program that will run on server machine under a user that has full write permissions on target directory. This one can also be easily written in Java
you can easily install the server program as a service on the server machine with sc and srvany according to this answer on ServerFault
If you use a client program, you could easily add a digital signature file with each copied file, but as I said above, it is poor security practice and add little if any security. At least the program should be executable and not readable, and the sources should be kept hidden. It is better to log the users that copied the file and ask them what happened is you find a problem.

Copying a file from a windows machine to another windows machine through java

I want to copy a file in local windows machine to another windows machine in the same LAN or Intranet using JAVA. I browsed and found that we can copy file using the copy command of ms-dos but it copies only to the shared folder of remote machine.
I don't want to copy to the shared folder but instead I want to copy to a folder inside C: drive which is not a shared one.
I tried using pscp command. It works for windows to linux file copying but not for windows to windows file copying.
The best way is to send the File with an selfwritten socket application.
You cant copy a non shared folder. But u can write a server client application to send the data over the network:
http://www.rgagnon.com/javadetails/java-0542.html
As far as i know, there are several ways to achieve it.
Provide two agents on the machine A and machine B, then you can copy the files to each machine by your own implement APIs.
Use the winrm protocol like chef does, more detail please refer to the below link.
You can also refer to some opensource project.
https://github.com/cloudsoft/winrm4j
https://github.com/OpenNMS/wsman
You cannot copy to a folder that it is not shared.
The operating system of the computer where you want to copy files will never allow you to write wherever you want for obvious security reasons.

query on file transfer using java socket programming

I need to move few files in a directory to another directroy in another machine. The source and destination directory names are known in advance. These directories will be in different Operating System(i.e. the source can be Linux and Destination can be in Windows).
To solve this, i wrote a Socket program in Java that successfully copies files from source directory to a destination directory(Tested in Windows OS). But this application needs program running in both the host and remote machine. So, my question is :
1) Is there any way to transfer files(in the ways described above) using Java Socket program without having a program running in the remote machine?
2) Whether file transfer using Java socket program, bypass firewal. In other words, if a firewall is present in the remote machine will that stop the transfer process?
3) Any alternative approach to transfer files(in the ways described above) using Java where only the host or remote need to run.?
Thanks in advance,
nks
1) You always need a program running on both machines. However, a way to get around this problem is to use a program already running on one of these machines.
e.g. If you make the directory a Windows share (assuming this is already running) you can mount this share on the Linux box (using smbfs), you can then copy files using cp This means you don't need Java on either end, but you need A program and A service (but it can be an existing one)
2) There isn't a way to by-pass a firewall unless your network is seriously mis-configured. This is the whole point of having one.
3) Once you mount either the Windows box on Linux, or the Linux files (using Samba) on Windows youc an copy files easily, even using Java. ;)

Fetch Windows system temperature with Java

I wrote a small hack that uses Java JNA and TCP sockets to transmit battery information from a Windows 7 system to other systems on my network, and I'd now like to add thermal monitoring functionality to it. Is it possible to monitor system thermal statistics from JNA?
Edit: Forgot to mention that I need a "pure Java" solution (but JNA and friends are permitted); I'm in a horrible environment that ensures I can't run applications that aren't digitally signed, I don't have access to the digital signature list, and I can't disable the digital signature lockdowns.
Most stuff I've read shows that manufacturers use WMI to expose this information. To allow your Java program to access WMA, check out this thread: Recommended libraries/howtos for using WMI with java?
If you could find a command line utility that works on windows to get sys temp you could call it from a processbuilder in Java.
Stephane

Moving a file from a windows Java application to a linux box

I'm currently doing a project that has to be run on a windows machine. The application creates a CSV file and saves it to the windows filesystem. I would like a way to transfer this file to a machine running linux into a directory selected by the user.
I am not asking for code (although if it helps then feel free :P ) but asking more for what protocols to use (ftp etc) and wether I need to take anything into account such as permissions in Linux as I am fairly in experienced with programming for linux file systems.
Thanks in advance :)
Can the windows machine see the linux filesystem? Is there a samba server running on the linux machine? If so, you can simply copy it from one filesystem to the other.
If not, you can try SCP or SFTP but you need to have the keys setup. Another way is to use Runtime.exec to copy the file using a windows specific command utility.
If all else fails, run a java process on the linux server and connect to it using sockets. Your windows client can write the file to the socket and it can be written out by the linux server.
I would try using SSH as SCP is a fairly standard and convenient way to transfer files securely. In Java you can use jssh amoungst other libraries.
If you don't want to do it programatically, I'd suggest using Rsync. It should be available for most *nix distros and you've got a Windows version called DeltaCopy that implements the same protocol.

Categories

Resources