Difference between revisions of "Home Library FTPClient"
(→Usage) |
(→Usage) |
||
Line 67: | Line 67: | ||
</source> | </source> | ||
− | == Change directory == | + | === Change directory === |
To changes the current working directory. | To changes the current working directory. | ||
Line 77: | Line 77: | ||
* '''path''': the path to the new working directory. | * '''path''': the path to the new working directory. | ||
− | === Example === | + | ==== Example ==== |
<source lang="java"> | <source lang="java"> | ||
FTPClient client = .. | FTPClient client = .. | ||
Line 84: | Line 84: | ||
</source> | </source> | ||
− | == Change directory up== | + | === Change directory up === |
To changes the current working directory to the parent one. | To changes the current working directory to the parent one. | ||
Line 91: | Line 91: | ||
</source> | </source> | ||
− | === Example === | + | ==== Example ==== |
<source lang="java"> | <source lang="java"> | ||
FTPClient client = .. | FTPClient client = .. | ||
Line 97: | Line 97: | ||
</source> | </source> | ||
− | == Create a directory == | + | === Create a directory === |
To create a new remote directory in the current working one. | To create a new remote directory in the current working one. | ||
Line 108: | Line 108: | ||
* '''description''': the description for the new directory. | * '''description''': the description for the new directory. | ||
− | === Example === | + | ==== Example ==== |
<source lang="java"> | <source lang="java"> | ||
FTPClient client = .. | FTPClient client = .. | ||
Line 114: | Line 114: | ||
</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="java"> | <source lang="java"> | ||
Line 125: | Line 125: | ||
* '''description''': a description for the file. | * '''description''': a description for the file. | ||
− | === Example === | + | ==== Example ==== |
<source lang="java"> | <source lang="java"> | ||
FTPClient client = .. | FTPClient client = .. | ||
Line 132: | Line 132: | ||
</source> | </source> | ||
− | == List a directory == | + | === List a directory === |
To list the content of the current directory: | To list the content of the current directory: | ||
<source lang="java"> | <source lang="java"> | ||
Line 138: | Line 138: | ||
</source> | </source> | ||
− | === Example === | + | ==== Example ==== |
<source lang="java"> | <source lang="java"> | ||
FTPClient client = .. | FTPClient client = .. | ||
Line 144: | Line 144: | ||
</source> | </source> | ||
− | == Remove files == | + | === Remove files === |
To remove files: | To remove files: | ||
<source lang="java"> | <source lang="java"> | ||
Line 153: | Line 153: | ||
* '''path''': the path of the file to remove. | * '''path''': the path of the file to remove. | ||
− | === Example === | + | ==== Example ==== |
<source lang="java"> | <source lang="java"> | ||
Line 161: | Line 161: | ||
</source> | </source> | ||
− | == Remove directories == | + | === Remove directories === |
To remove directories: | To remove directories: | ||
<source lang="java"> | <source lang="java"> | ||
Line 170: | Line 170: | ||
* '''path''': the path of the directory to remove. | * '''path''': the path of the directory to remove. | ||
− | === Example === | + | ==== Example ==== |
<source lang="java"> | <source lang="java"> |
Revision as of 12:45, 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 changes the current working directory.
- Change Directory Up: to changes the current working directory to the parent one.
- 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:
FTPClient
A FTPClient is created with:
FTPClient client = new FTPClient();
Run the test
To check the correct behavior of all features:
FTPClient client = .. client.test();
Current Directory
To know the current working directory:
public String currentDirectory()
Example
FTPClient client = .. client.currentDirectory();
Change directory
To changes the current working directory.
void changeDirectory(String path)
Where:
- path: the path to the new working directory.
Example
FTPClient client = .. String mySubFolder = .. client.changeDirectory(mySubFolder);
Change directory up
To changes the current working directory to the parent one.
void changeDirectoryUp()
Example
FTPClient client = .. client.changeDirectoryUp();
Create a directory
To create a new remote directory in the current working one.
void createDirectory(String directoryName, String description)
Where:
- directoryName: the name of the new folder.
- description: the description for the new directory.
Example
FTPClient client = .. client.currentDirectory();
Upload a file
To upload a file, if it does not already exist:
void upload(File file, String name, String description)
Where:
- file: the file to upload.
- name: a name for the file
- description: a description for the file.
Example
FTPClient client = .. File myFile = .. client.upload(myFile, myFile.getName(), "my new file");
List a directory
To list the content of the current directory:
FTPFile[] list()
Example
FTPClient client = .. FTPFile[] myFiles = client.list();
Remove files
To remove files:
void deleteFile(String path)
Where:
- path: the path of the file to remove.
Example
FTPClient client = .. String myFilename = .. client.deleteFile(myFilename);
Remove directories
To remove directories:
void deleteDirectory(String path)
Where:
- path: the path of the directory to remove.
Example
FTPClient client = .. String myDir = .. client.deleteDirectory(myDir);