Access remote programs and files securely from Android or Java Desktop applications

  • Easy file upload/download & RPC programming.
  • Optimized and designed to manage heavy traffic.
  • Supports file chunking & automatic recovery.
  • Easy access of remote files with java.io.OutputStream, java.io.InputStream and java.io.File API.
  • Immediate Setup. Power of FTP and RMI without the hassles.
  • Built-in security.
  • Free and Open Source Software. (LGPL License).

KRemote Files - previously Awake FILE - is a secure Open Source client/server framework that allows to program very easily remote file access, file uploads/downloads, and RPC through HTTP.

File transfers include powerful features like file chunking and automatic recovery mechanism.

KRemote Files allows 3 types of operations:

  1. Accessing remote files with java.io.File syntax.
  2. Files upload and download using java.io.OutputStream and java.io.InputStream syntax.
  3. Secure RPC calls.


Accessing Remote Files

We first create a RemoteSession that establishes a link with the KRremote Files server:

// Parameters for connection to our remote server
String url = "https://www.acme.com/ServerFileManager";
String username = "username";
char[] password = { 'd', 'e', 'm', 'o' };

// Establish a session with the remote server
RemoteSession remoteSession = new RemoteSession(url, username,
	password);


We can now create a RemoteFile and use it as if it were a java.io.File:

// Display info on our remote /mydir/Koala.jpg
RemoteFile koala = new RemoteFile(remoteSession, "/mydir/Koala.jpg");

System.out.println("Display remote " + koala + " info...");
System.out.println("last modified: " + new Date(koala.lastModified()));
System.out.println("length       : " + koala.length());
System.out.println("Parent       : " + koala.getParent());


We display the files located in remote directories with RemoteFile.listFiles(), which acts as java.io.File.listFiles() method:

// List all files located in remote directory /mydir
RemoteFile remoteDir = new RemoteFile(remoteSession, "/mydir");
RemoteFile[] remoteFiles = remoteDir.listFiles();
System.out.println();
System.out.println("All files located in " + remoteDir + ": "
	+ Arrays.asList(remoteFiles));


Files Upload and Download

We want now to upload a new file to remote mydir. We simply use a RemoteOutputStream which implements a java.io.OutputStream:

// Upload user.home/Tulips.jpg to remote directory /mydir
String userHome = System.getProperty("user.home") + File.separator;
File file = new File(userHome + "Tulips.jpg");

Path path = file.toPath();
try (OutputStream outputStream = new RemoteOutputStream(remoteSession,
    "/mydir/Tulips.jpg");) {
    Files.copy(path, outputStream);
}


We have of course a complete access to all java.io.OutputStream methods; this will be helpful if we want to create a nice progress indicator for our users. This is the same Tulips.jpg upload with alternate syntax using only stream methods:

File file = new File(userHome + "Tulips.jpg");

try (InputStream in = new BufferedInputStream(
    new FileInputStream(file));
    OutputStream out = new RemoteOutputStream(remoteSession,
    	"/mydir/Tulips.jpg")) {
    byte[] buffer = new byte[4096];
    int n = 0;
    while ((n = in.read(buffer)) != -1) {
    	out.write(buffer, 0, n);
    }
}


Download is as straightforward, we use a RemoteInputStream which implements a java.io.InputStream:

File file = new File(userHome + "Tulips.jpg");

try (InputStream in = new RemoteInputStream(remoteSession,
    "/mydir/Tulips.jpg");
    OutputStream out = new BufferedOutputStream(
    	new FileOutputStream(file));) {
    byte[] buffer = new byte[4096];
    int n = 0;
    while ((n = in.read(buffer)) != -1) {
    	out.write(buffer, 0, n);
    }
}


Secure RPC Calls

KRemote Files include a simple to use RPC mechanism, without stubbing, code generation, XML or JSON. It is secured so that only authenticated users can call remote Java methods.

This is a Calculator class located on remote server:

package com.kremotefiles.quickstart;
import org.kawanfw.file.api.server.ClientCallable;

/**
 * A simple calculator to be called from the client side. 
 * Requires the client to be authenticated.
 */
public class Calculator implements ClientCallable {


    public Calculator() {
    }

    public int add(int a, int b) {
	return (a + b);
    }
}

The ClientCallable interface is a marker interface that indicates to KRemote Files server that Calculator class is callable only by valid and authenticated users.

We use RemoteSession.call method to call the add method from client side:

String resultStr = remoteSession
	.call("com.kremotefiles.quickstart.Calculator.add", 20, 22);
int result = Integer.parseInt(resultStr);

System.out.println("Result: " + result);

Evaluate by downloading KRemote Files and following our Quick Start.