How can I access to a file exists on remote machine? - java

I want to access to a file (read) that exist on a remote machine from my code JAVA,what I need to do that?
just the IP of the machine and the location of the file or I need somthing else?
Thank you

There are some choices:
Via a 'mapped' directory using SMB/Samba to the remote machine and you can then access the file using the normal File class.
Via a Web Server where read access is easier (if you require write access then you are looking at something like WebDAV). This requires the use of the HTTP protocol in your code.
Via FTP or SFTP network protocols to access the file. This obviously requires the use of (S)FTP classes to access the file.
The first option is easiest from a coding point-of-view.

If both the Java code and the remote file are on Linux machines, you can also choose NFS.
As always you need to start a server which serves the file - you need nfsd to share the directory containing that file on the remote machine.
On the machine where your Java code will run, mount the shared nfs
Here is a brief introduction of using nfs on Ubuntu.
If you prefer FTP/HTTP, you will be interested in Apache commons vfs library, which supports many protocols including FTP, SFTP, HTTP, etc.

First of all, you need a service on the remote machine that serves files. Once a file-serving service exists, you communicate with the service using its protocol.
Assuming the client-server model, you have several choices on the remote (server) side. First of all, you can design your own protocol, write a server, deploy it on the remote machine and write a client (in Java) which will talk with the server using the designed protocol. However, there many off-the-shelf solutions (protocols + servers + Java client libraries) that might be used. Three protocols which come to mind right now: TFTP, FTP and SMB.
If your aim is simplicity, I recommend TFTP: there are free TFTP servers for UNIX, Windows and Mac OS X, and there is Apache Commons Net Java library on the client side.

Related

SFTP to FTP bridge

I would like to connect with an SFTP client to an FTP server using java. I know the two technologies have nothing to do with each-other. What I'm trying to accomplish is to connect to an FTP server via the internet with out using two ports or changing the server configuration.
Is there any SFTP->FTP bridge in java it would be great. If not, how can I accomplish that ?
I would like to incorporate this in an exciting java server so hence, java based solutions are preferred. If there is some standalone software which you can control via code than it should support windows and *nix.
(Since SFTP is just the means here, a similar WebDav solution will also work)
You could go with trial and error. Try this out see if it works.
How to retrieve a file from a server via SFTP?

Streaming log files to remote client

I have a Java app running on a remote server (debian linux). The app logs runtime informations to files.
Once in a while, the support needs to analyze the logs using a client tool (not running on the server, but on the support's desktop). The tool then needs remote access to
old log files on the server
the current log file (growing in real time)
I'm searching a good (=standard, flexible, secure, well debugged etc) way to stream these past and present log messages to my client tool.
How would go about doing this?
Does a library exist, which provides this service?
Can syslog be adapted to do this?
Edit: For privacy reasons, the log files should be stored on the remote server only and not generally sent to a central logging service.
Why not use Log4j's capability as a publisher of log files to a remote server via TCP? Log4j is a standard Java logging tool (well-known/well-documented) and setting up the remote connectivity is pretty straightforward.
I've used this in the past to transmit across networks and collate log files from multiple machines in one common searchable directory structure (very useful in grid environments when you don't know where your processes could be running)
See this page for more details.
The simplest approach is likely to setup samba on the Linux box so you can access the logs remotely as they are updated without having to copy them.
You could use rsync. This allows you to securely copy changes to files between machines. i.e. an appending file would only copy the changes since the last rsync. Note: you have to run it repeatedly to keep seeing updates.
If the tools could be modified to support SSH e.g. via VFS, then you could access the remote files as if they were local.

How can i upload file in remote machine(LAN) using java

How can i upload file in remote machine(LAN) using java program.I want to connect remote machine in LAN and upload file from my local machine to remote machine.So please tell me how can i do this.
I suggest you use JSch. You'll be able to connect easily to a remote machine and it allows you to execute file transfer using sftp for example.
It's hard to find a real documentation for JSch, but the various examples they give on their site are really complete and in general sufficient to help one succeeding in his task.
You probably want an HTTP client library for Java, to issue an HTTP POST request. (I assume the remote machine has some web server to upload the file).
Google gives several suggestions, like Hc.Apache

Java upload files to remote linux server WITHOUT ftp or scp

I am trying to write a program in java to upload some files from my local environment to a remote server. I cannot use FTP because there is no FTP server installed on that instance. Also port 22 is closed so I can't use scp either.
Is there any other way to approach this?
Thanks in advance guys!
You need something on the serverside, a program, which is waiting for your file. You can't just send something there.
An open port is always a program running, waiting for a connect.
So a couple of possible protocols are rsync and WebDav. But at the end of the day I recommend one of two options. Get ssh installed, or use rsync.
Talk to the unix admin and work something out.
Even linux servers sometimes use smb/cifs (the Microsoft technique to share files and folders) to publish data. The samba team provides a 100% Java library to access those: http://jcifs.samba.org/

Searching for FTP over SSH (not SFTP) Server and Java library

As a requirement in a customer project is to support FTP over SSH I'm currently looking for 2 things:
1. A SecureFTP-Server for testing purpose
2. A Java library which supports FTP over SSH.
When searching for a solution the main problem is that ALL implementations are also transfering the files encrypted (and therefore implementing SSH FTP) - this is NOT what I'm looking for. As described here (http://de.wikipedia.org/wiki/Secure_File_Transfer_Protocol - german only) only the authentication and file listing should be encrypted - the file transfer itself is not encrypted.
Please don't try to convince me to use SSH FTP (or other secure protocolls like FTPS) - I need to use the more insecure version as the customer uses it...
EDIT: FTP over SSH exactly describs what I'm searching for.
If FTP over SSH is what you're after, one of the projects mentioned at the Wikipedia page on FTP over SSH is FONC, which is both a client and a server, written in Java, and licensed under GPLv2.
This looks like what you're looking for, check if the license is applicable to your project.

Categories

Resources