Dsm for java is an open source java library for Synology DSM Api, it's basically a wrapper for the API. you can find all information about the api here available for developers who want's to know how the api works.
If you find yourself on this page, it means that you have a java project and you need to communicate with your Nas Synology. This wrapper can be a great startup for that. I am trying to build the most complete wrapper for synology. You are welcome if you want to help me, I will be greatfull.
This project is written in java 8. you can only use it in a project that uses java 8 and above. if you want to use it in any environment, make sure you the right JVM installed on the machine.
Most of the tests need an actual Synology Nas. Make sure you have the Synology in the same network as your server, or set a DDNS to access your synology easily from internet. Look at this official tutorial : How to make Synology NAS accessible over the Internet Don't forget to use the firewall to restrict unknown ip from accessing your portal.
you have to define an environment file in your resource folder
env.properties in which you have to put this lines :
How to use it
add the maven repository to your pom.xml
<dependency> <groupId>com.github.ccenyo</groupId> <artifactId>DSM4J</artifactId> <version>1.2.1</version> </dependency>
DsmAuth auth = DsmAuth.fromResource("env.properties"); DsmFileStationClient client = DsmFileStationClient.login(auth); //get the list of all folders in a ROOT_FOLDER = /homes Response<DsmListFolderResponse> response = client.ls(ROOT_HOME).call(); //Files response.getData().getFiles();
you can create an
auth object in different ways
DsmAuth auth = DsmAuth.fromResource("env.properties");
DsmAuth dsmAuth = DsmAuth.fromFile(file);
DsmAuth dsmAuth = DsmAuth.of(host, port, username, password);
Non blocking usage
Some features are non-blocking you have to start the request and then check the status before getting the result
Response<DsmDeleteResponse> deleteResponse = client.advancedDelete() .addFileToDelete(ROOT_FOLDER+"/"+fileToDownload.getName()) .start(); Response<DsmDeleteResponse> statusResponse = client.advancedDelete() .taskId(deleteResponse.getData().getTaskid()) .status(); // you can stop the request if you don't want the result anymore client.advancedDelete() .taskId(deleteResponse.getData().getTaskid()) .stop();
||login||Login to synology dsm|
|List all shared folders||
||list_share||List all shared folders, and get detailed file information|
|List of folders/files||
||list||Enumerate files in a shared folder, and get detailed file information|
||upload||Upload content to the cloud.|
||download||Download files/folders. If only one file is specified, the file content is responded. If more than one file/folder is given, binary content in ZIP format which they are compressed to is responded.|
|Delete a file or folder||
||delete||Delete file synchoniously|
|Delete a file or folder||
||start/status/stop||Delete file asynchoniously, non-blocking method|
|Rename a file or folder||
||rename||rename files or folders|
|Copy or move file/folder||
||start/status/stop||copy or move folder or file asynchroniously|
||create||Create new Folder|
|Favorite to file/folder||
||add,edit,delete, replace, clrear||add favorite on folder or file|
|Share file of folder||
||create,edit,delete, info, clear_invalid||Share a file of folder ans get a link|
|Get file or folder size||
||start/status/stop||get the size of file or folder|
|Search for file of folder||
||start/list/stop||look for file or folder and get all informations|
If you don't know how to use the methods, feel free to look at the tests, i always make sure to use the methods in different ways in the tests.
##RoadMap I will be completing new methods regularely
- Adding rest of methods for FileStation : Thumb, VirtualFolder, MD5, CheckPermission, Extract, Compress, BackgroundTask
- Adding features for DownloadStation
- Adding features for AudioStation
- Cenyo Medewou - firstname.lastname@example.org.
This project is licensed under the MIT License - see the LICENSE file for details