Pages

Thursday, 5 June 2014

Transfer Files Between two Systems Over User Defined Ports

This is a continuation of my post for sending multiple files over a socket connection. Spent some time over the same to explore the possibility of connecting two systems over a port of the users choice. The output code is a command line code, involving a Socket Server and Client which can reside on either system. It can both push a file as well as receive it.
The code sample is just an attempt to transfer the file/files over the network or within the system.

What is available:

  • Copy a File from source to destination.
  • Copy a Folder from source to destination (subfolders are ignored).
  • Copy a Folder from source to destination (recursive).
  • Parallel copy of files.
Note: The files can be copied from either systems, ie it can either send the files out or request the files from the other system, so a two way copy is possible.

What can be Improved:
  • Secure the Server socket to accept connection from predefined devices/ip address
  • Use a token to validate the request (either a certificate/encrypted token etc), thus allowing only those with actual credentials to transfer.
Source:

The source code is available here.

Jar:
Have prepared a Jar which can be used as is (compiled on jre 1.7) to copy the files.

Steps To Run:

  1. Copy the zip file on the source system as well as the destination system (one setup ie enough if file has to be transferred within the same machine).
  2. The folder contains three bat files:
    • filecopyserver.bat -- This can be run as is and will start a Listening socket on port 50000. This can be changed by adding the port as an argument in this file.
    • getfilesclient.bat -- This can be executed if the requirement is to pull the file from a source to a target, the source and the target would have to be updated in this file.
    • putfilesclient.bat -- This can be executed if the file is on the system initiating the transfer and has to be moved to the other system.


Client Mode Setting:
  1. The getfilesclient and putfilesclient accepts the following arguments:
    • Ip Address/hostname where the listening service is running.
    • Port on which the service is listening
    • Source Folder/File
    • Target Folder/File
    • Number of parallel threads
  2. In addition the following optional arguments are supported on the client side (it can be passed as -r -o or in a single argument -ro/-or)
    • -r -- For following the filetree and copy all files and folders recursively. If not provided, the copy will not be recursive
    • -o -- Overwrite even if the files are already present (a checksum is done using CRC32 to compare whether the files in source and target are same). Default behaviour is not to overwrite.
Server Mode Setting:
  1. The filecopyserver.bat accepts the port as an optional argument. Default port if not provided is 50000. The port defined here should be the same as the one used while running the client.

No comments:

Post a Comment