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

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.

Related

OSX : how to access NAS files in Java

My Environment is OSX BIG SUR.
For space reasons, I need to move files from my Hard disk to a NAS (on my local network).
The current applications accessing these files (en read mode) were developed in Java.
I suppose I should use a Mount command in programs with the SMB protocol, but how to do this without be prompted for password with the SUDO command ?
So I'm looking for some examples.
You have a few ways to go:
Have java execute the smb mount command
This is a walking disaster; you don't want your java process to gain root privileges to do this.
Have java be an smb client
Possible... use JCifs-ng. The docs are lacking, and this would have been a lot simpler if it had integrated into the new files / filesystem API, but it doesn't. You'll have some coding to do.
Learn sysops
All you really need is for the OS to have that samba share mounted someplace and then, to your java process, it's all just files on a filesystem. Don't make the smb mount happen in java, ensure it's already set up before your java process even starts.

How to write binary file in remote machine using j-interop?

I am using J-interop and java to interact with window remote machine, I am able to connect to the remote window machine using j-interop but do not know how to write binary files to window remote machine. If any one have sample code to do that it will be highly appreciated.
If you can use another Java library then I would suggest you to look at JCIFS. http://jcifs.samba.org/
I have success to use this library to perform file operations from a Linux node to Windows node (XP, 2003 Server, 7 and 2008 Server).
Good luck

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. ;)

Automate download logs from server via ssh file transfer to local machine

I need help regarding how to Automate download logs from server via ssh file transfer to local machine.Currently I am downloading logs via login to ssh tool and select the path of the logs and select all the logs and then drag and drop them to local drive but this takes time on VPN.
Is there any way to create batch file or run any Java program to downloads all logs just in one line command or single execution automatically.I have tried to check this google but with scp and ftp command I am not able to proceed further.Please suggest.
If you're on Windows, I'd recommend WinSCP's easy scripting.
Just write your script of where to connect, where to navigate to, what to collect and where to copy your file in your machine. You can even copy to another server. All in one script. Examples are easy to follow in the link.
You can also run a simple script that does the work in one line:
winscp.exe /console /command "option batch on" "open rahul#logsserver.com" "get 02012011logs.txt d:\" "exit"
What is the OS you are using for your client? If your client machine is *nix variant, you could write a simple bash script, which when paired with SSH Keys, will allow you your one command downloader.
For a windows variant, you could do similar with a batch script, schedule tasks and pscp w/ pagent saving a private key in memory.
Of course none of this deals with starting up or tearing down the vpn.
Write a batch file that uses pscp to download the files you need. Set up public-key authentication to skip password entry. Enable ssh compression for faster download. Automate it via cron. Theoretically one should be able to use the vpn only for the batch file, practically very difficult to set up that way.
The best option for you would be to write a cron job that copies the log using scp on the regular intervals you want.
However, if you do want to do it in Java. Go for JSch.
Side-note: none of the options above gets you rid of the VPN. You will have to be on VPN to get file transferred, if it's required. So, stay connected to VPN while you are transferring your files in whatever way you like.
Edit
You should update your question with the platform that you're using. My previous answer was assuming that you're on Unix based.
If you are using Windows, you can write a batch script that uses PSCP to transfer the files to your local machine. You can set it as Scheduled Task in Windows to run periodically.

Categories

Resources