Difference between revisions of "Home Library FTPClient"
(→Start) |
(→Usage) |
||
Line 40: | Line 40: | ||
== Start == | == Start == | ||
− | + | A FTPClient is created with: | |
<source lang="java"> | <source lang="java"> | ||
Line 48: | Line 48: | ||
== Run the test == | == Run the test == | ||
To check the correct behavior of all features: | To check the correct behavior of all features: | ||
− | <source lang=" | + | <source lang="java"> |
− | + | client.test(); | |
</source> | </source> | ||
− | === | + | == Current Directory == |
− | + | To know the current working directory: | |
− | + | ||
− | + | <source lang="java"> | |
− | + | public String currentDirectory() | |
− | + | </source> | |
− | + | ||
− | + | === Example === | |
− | + | <source lang="java"> | |
− | + | client.currentDirectory(); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</source> | </source> | ||
== Create a directory == | == Create a directory == | ||
− | To create a directory | + | To create a new remote directory in the current working one. |
− | <source lang=" | + | <source lang="java"> |
− | + | void createDirectory(String directoryName, String description) | |
</source> | </source> | ||
− | + | Arguments: | |
− | * ''' | + | * '''directoryName''': the name of the new folder. |
− | + | * '''description''': the description for the new directory. | |
− | + | ||
− | + | ||
− | * '''description''': the description | + | |
=== Example === | === Example === | ||
− | <source lang=" | + | <source lang="java"> |
− | + | client.currentDirectory(); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</source> | </source> | ||
== Upload a file == | == Upload a file == | ||
To upload a file, if it does not already exist. | To upload a file, if it does not already exist. | ||
− | <source lang=" | + | <source lang="java"> |
− | + | void upload(File file, String name, String description) | |
</source> | </source> | ||
Mandatory arguments: | Mandatory arguments: | ||
− | * ''' | + | * '''file''': the file to upload. |
− | + | * '''name''': a name for the file | |
− | + | * '''description''': a description for the file. | |
− | * ''' | + | |
− | * ''' | + | |
=== Example === | === Example === | ||
− | <source lang=" | + | <source lang="java"> |
− | + | File myFile = .. | |
− | + | client.upload(myFile, myFile.getName(), "my new file"); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</source> | </source> | ||
Revision as of 12:14, 3 May 2016
Introduction
Home Library FTPClient is a Java library providing a simple interface to Home Library WebApp.
This library has following features:
- Current Directory: returns the pathname of the current working directory.
- Change Directory: to create a directory in the root or in a subfolder.
- Create Directory: to create a directory in the root or in a subfolder.
- List Directory: to list the content of a directory.
- Upload file: to upload a file in a directory.
- Remove files and folders: to remove a file or a directory (including subdirectories).
- Test: a simple test to check the correct behavior of the features above.
The following sections will discuss each of these commands in turn, and discuss how to use them with Home Library FTPClient.
Configuration File
Home Library CLI is equipped with a simple configuration file to set the parameters and initial settings.
The fields are:
- URL_REPOSITORY: the URL of Home Library WebApp.
- USERNAME: username to connect to Home Library WebApp.
- PASSWORD: password to connect to Home Library WebApp.
- LOGIN: the portal login of the user who is using the library.
- ROOT_PATH : the ROOT of the VRE folder where the files and directory will be created.
The Configuration File cannot be modified by the final user, but it allows to use the CLI in different context.
Usage
Prerequisites
Home Library FTPClient is a jar-with-depencencies, you only need a Java 7 JDK.
Download the latest release from here:
Start
A FTPClient is created with:
FTPClient client = new FTPClient();
Run the test
To check the correct behavior of all features:
client.test();
Current Directory
To know the current working directory:
public String currentDirectory()
Example
client.currentDirectory();
Create a directory
To create a new remote directory in the current working one.
void createDirectory(String directoryName, String description)
Arguments:
- directoryName: the name of the new folder.
- description: the description for the new directory.
Example
client.currentDirectory();
Upload a file
To upload a file, if it does not already exist.
void upload(File file, String name, String description)
Mandatory arguments:
- file: the file to upload.
- name: a name for the file
- description: a description for the file.
Example
File myFile = .. client.upload(myFile, myFile.getName(), "my new file");
List a directory
To list the content of a directory.
java -jar home-library-cli-<$version>-jar-with-dependencies.jar ls [directory]
Optional arguments:
- directory: the absolute path of the directory to list (by default the content of the ROOT_PATH will be shown).
Example
user@my-pc:~$ java -jar home-library-cli-1.0.0-20160324.155028-1-jar-with-dependencies.jar ls myFolder param N.0: ls param N.1: myFolder Response Code : 200 1 items found. myFolder/image.jpg
Remove files or directories
To remove files or directories:
java -jar home-library-cli-<$version>-jar-with-dependencies.jar rm fileOrDirectory
Mandatory arguments:
- fileOrDirectory: the absolute path of the directory or file to remove.
Example
Remove a file:
user@my-pc:~$ java -jar home-library-cli-1.0.0-20160324.155028-1-jar-with-dependencies.jar rm myFolder/image.jpg param N.0: rm param N.1: myFolder/image.jpg Response Code : 200 /myFolder/image.jpg deleted.
Remove a directory:
user@my-pc:~$ java -jar home-library-cli-1.0.0-20160324.155028-1-jar-with-dependencies.jar rm myFolder param N.0: rm param N.1: myFolder Response Code : 200 myFolder deleted.