filestation

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 8 Imported by: 1

README

QNAP File Station API for Go

This library provides access to the QNAP File Station API (http://www.qnap.com).

Click here to open the documentation.

Usage

To use the API, simply create a new session:

import "github.com/nine-lives-later/go-qnap-filestation"

func main() {
    session, _ := filestation.Connect("storage:8443", "admin", "admin", nil)

    session.Logout()
}

Authors

We thank all the authors who provided code to this library:

  • Felix Kollmann
  • marvin + konsorten GmbH (who sponsored this library in 2018)
  • Scott Ware (v1.0 of this library is loosely based on the go-bigip package)

License

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package filestation provides access to the QNAP File Station API (http://www.qnap.com).

More information is available on the project website: https://github.com/nine-lives-later/go-qnap-filestation/

QNAP File Station API documentation can be downloaded here: http://download.qnap.com/dev/QNAP_QTS_File_Station_API_v4.1.pdf .

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigOptions

type ConfigOptions struct {
	APICallTimeout              time.Duration
	IgnoreInvalidSSLCertificate bool
}

ConfigOptions contains some advanced settings on server communication.

type FileListEntry

type FileListEntry struct {
	Name              string `json:"filename,omitempty"`
	FullPath          string
	Exists            int    `json:"exist,omitempty"`
	IsFolder          int    `json:"isfolder,omitempty"`
	FileSize          int64  `json:"filesize,omitempty,string"`
	Group             string `json:"group,omitempty"`
	Owner             string `json:"owner,omitempty"`
	IsCompressed      int    `json:"iscommpressed,omitempty"`
	Privilege         string `json:"privilege,omitempty"`
	PrivilegeEx       int    `json:"privilege_ex,omitempty"`
	FileType          int    `json:"filetype,omitempty"`
	ModifiedDate      int    `json:"epochmt,omitempty"`
	HasStickyBit      int    `json:"sticky_bit,omitempty"`
	IsFolderEncrypted int    `json:"encrypt_folder,omitempty"`
	ProjectionType    int    `json:"projection_type,omitempty"`
}

type FileStationSession

type FileStationSession struct {
	// contains filtered or unexported fields
}

FileStationSession is a container for our session state.

func Connect

func Connect(host, username, password string, configOptions *ConfigOptions) (*FileStationSession, error)

Connect sets up our connection to the QNAP system.

func (*FileStationSession) Close added in v1.1.0

func (s *FileStationSession) Close() error

func (*FileStationSession) CreateFolder

func (s *FileStationSession) CreateFolder(path string) (bool, error)

CreateFolder creates a new folder. The base directory must exists.

func (*FileStationSession) DeleteFile

func (s *FileStationSession) DeleteFile(path string) (bool, error)

DeleteFile deletes a file or folder.

func (*FileStationSession) DeleteFileNoRecycleBin

func (s *FileStationSession) DeleteFileNoRecycleBin(path string) (bool, error)

DeleteFileNoRecycleBin deletes a file or folder without moving them to the recycling bin.

func (*FileStationSession) EnsureFolder

func (s *FileStationSession) EnsureFolder(path string) (int, error)

EnsureFolder creates a new folder and its parent directories.

func (*FileStationSession) GetFileList

func (s *FileStationSession) GetFileList(path string) ([]FileListEntry, error)

GetFileList retrieves the list of files and folders of a share.

func (*FileStationSession) GetFileStat

func (s *FileStationSession) GetFileStat(path string) (*FileListEntry, error)

GetFileStat checks if a file or folder exists.

func (*FileStationSession) GetShareList

func (s *FileStationSession) GetShareList() ([]FolderListEntry, error)

GetShareList retrieves the list of shares.

func (*FileStationSession) Login

func (s *FileStationSession) Login(username, password string) error

Login perform the authentication against the QNAP storage. Any existing session will be logged-out, first.

func (*FileStationSession) Logout

func (s *FileStationSession) Logout() error

Logout invalidates the session.

func (*FileStationSession) SetPrivilege added in v1.2.0

func (s *FileStationSession) SetPrivilege(path string, privilege Privilege, recursive bool) error

SetPrivilege changes file-system level permissions of a file or folder (chmod).

func (*FileStationSession) String

func (s *FileStationSession) String() string

String returns the session's hostname.

type FileStationStatus added in v1.1.0

type FileStationStatus int
const (
	WFM2_FAIL                        FileStationStatus = 0  // UNKNOW ERROR
	WFM2_DONE                        FileStationStatus = 1  // SUCCESS
	WFM2_SUCCESS                     FileStationStatus = 1  // SUCCESS
	WFM2_FILE_EXIST                  FileStationStatus = 2  // FILE EXIST
	WFM2_AUTH_FAIL                   FileStationStatus = 3  // Authentication Failure,認 證 失 敗
	WFM2_PERMISSION_DENY             FileStationStatus = 4  // Permission Denied,存 取 拒 絕
	WFM2_FILE_NO_EXIST               FileStationStatus = 5  // FILE/FOLDER NOT EXIST,檔 案 不 存 在
	WFM2_SRC_FILE_NO_EXIST           FileStationStatus = 5  // FILE/FOLDER NOT EXIST,檔 案 不 存 在
	WFM2_EXTRACTING                  FileStationStatus = 6  // FILE EXTRACTING,檔 案 解 壓 縮 中
	WFM2_OPEN_FILE_FAIL              FileStationStatus = 7  // FILE IO ERROR,檔 案 寫 入 時 發 生 錯 誤
	WFM2_DISABLE                     FileStationStatus = 8  // Web File Manager is not enabled.,Web File Manager尚 未 啟 用
	WFM2_QUOTA_ERROR                 FileStationStatus = 9  // You have reached the disk quota limit.,您 的 磁 碟 容 量 配 額 已 滿
	WFM2_SRC_PERMISSION_DENY         FileStationStatus = 10 // You do not have permission to perform this action.,您 沒 有 權 限 進 行 此 項 操 作
	WFM2_DES_PERMISSION_DENY         FileStationStatus = 11 // You do not have permission to perform this action.,您 沒 有 權 限 進 行 此 項 操 作
	WFM2_ILLEGAL_NAME                FileStationStatus = 12 // 名 稱 不 合 法。因 為 其 中 含 有 以 下 字 元:n " + = / \ : | * ? < > ; [ ] % , ` ' 字 元 或 特 殊 字 首 "_sn_" 和 "_sn_bk"。
	WFM2_EXCEED_ISO_MAX              FileStationStatus = 13 // The maximum number of allowed ISO shares is 256. Please unmount an ISO share first.//最 大 支 援 的 映 像 檔 資 料 夾 是256。請 先 卸 載 一 個 映 像 檔 資 料 夾。
	WFM2_EXCEED_SHARE_MAX            FileStationStatus = 14 // The maximum number of shares is going to be exceeded.分 享 的 數 目 已 到 達 最 大 的 分 享 數 目 的 限 制
	WFM2_NEED_CHECK                  FileStationStatus = 15
	WFM2_RECYCLE_BIN_NOT_ENABLE      FileStationStatus = 16
	WFM2_CHECK_PASSWORD_FAIL         FileStationStatus = 17 // Enter password,請 輸 入 密 碼
	WFM2_VIDEO_TCS_DISABLE           FileStationStatus = 18 // 媒 體 櫃 未 啟 動
	WFM2_DB_FAIL                     FileStationStatus = 19 // The system is currently busy. Please try again later.系 統 忙 碌 中,請 再 試 一 次。
	WFM2_DB_QUERY_FAIL               FileStationStatus = 19 // The system is currently busy. Please try again later.系 統 忙 碌 中,請 再 試 一 次。
	WFM2_PARAMETER_ERROR             FileStationStatus = 20 // There were input errors. Please try again later.
	WFM2_DEMO_SITE                   FileStationStatus = 21 // Your files are now being transcoded.
	WFM2_TRANSCODE_ONGOING           FileStationStatus = 22 // Your files are now being transcoded.您 的 檔 案 正 在 轉 檔 中。
	WFM2_SRC_VOLUME_ERROR            FileStationStatus = 23 // An error occurred in the source file. Please check and try again later.資 料 來 源 讀 取 異 常,請 檢 查 資 料 來 源 後 再 試 一 次。
	WFM2_DES_VOLUME_ERROR            FileStationStatus = 24 // A write error has occurred at the target destination. Please check and try again later.目 的 地 寫 入 異 常,請 檢 查 後 再 試 一 次。
	WFM2_DES_FILE_NO_EXIST           FileStationStatus = 25 // The target destination is unavailable. Please check and try again later.目 的 地 路 徑 不 存 在,請 檢 查 後 再 試 一 次。
	WFM2_FILE_NAME_TOO_LONG          FileStationStatus = 26 // The file name is too long. Please use a shorter one (maximum: 255 characters). Note that this length is for English characters. For non-English file names, please keep them shorter than the length above.名 稱 長 度 超 過 限 制,請 將 長 度 控 制 在255字 元 之 內。請 注 意,此 長 度 為 英 文 字 元 長 度。故 針 對 非 英 語 語 系 的 檔 案 名 稱,請 注 意 勿 超 過 此 長 度。
	WFM2_FOLDER_ENCRYPTION           FileStationStatus = 27 // This folder has been encrypted. Please decrypt it and try again.資 料 夾 已 加 密,請 先 解 密。
	WFM2_PREPARE                     FileStationStatus = 28 // Processing now, please wait.任 務 進 行 中,請 稍 等。
	WFM2_NO_SUPPORT_MEDIA            FileStationStatus = 29 // This file format is not supported.不 支 援 開 啟 這 類 型 的 格 式。
	WFM2_DLNA_QDMS_DISABLE           FileStationStatus = 30 // Please enable the <qtag>DLNA Media Server</qtag>.請 先 啟 動 <qtag>DLNA Media Server</qtag> 。
	WFM2_RENDER_NOT_FOUND            FileStationStatus = 31 // Cannot find any available DLNA devices.目 前 找 不 到 任 何 可 用 的 播 放 裝 置。
	WFM2_CLOUD_SERVER_ERROR          FileStationStatus = 32 // The SmartLink service is currently busy. Please try again later.SmartLink服 務 忙 碌 中,請 再 試 一 次。
	WFM2_NAME_DUP                    FileStationStatus = 33 // That folder or file name already exists. Please use another name.
	WFM2_EXCEED_SEARCH_MAX           FileStationStatus = 34 // 搜 尋 結 果 超 過1000筆
	WFM2_MEMORY_ERROR                FileStationStatus = 35
	WFM2_COMPRESSING                 FileStationStatus = 36
	WFM2_EXCEED_DAV_MAX              FileStationStatus = 37
	WFM2_UMOUNT_FAIL                 FileStationStatus = 38
	WFM2_MOUNT_FAIL                  FileStationStatus = 39
	WFM2_WEBDAV_ACCOUNT_PASSWD_ERROR FileStationStatus = 40
	WFM2_WEBDAV_SSL_ERROR            FileStationStatus = 41
	WFM2_WEBDAV_REMOUNT_ERROR        FileStationStatus = 42
	WFM2_WEBDAV_HOST_ERROR           FileStationStatus = 43
	WFM2_WEBDAV_TIMEOUT_ERROR        FileStationStatus = 44
	WFM2_WEBDAV_CONF_ERROR           FileStationStatus = 45
	WFM2_WEBDAV_BASE_ERROR           FileStationStatus = 46
)

func (FileStationStatus) Error added in v1.1.0

func (s FileStationStatus) Error() string

type FolderListEntry

type FolderListEntry struct {
	Path          string `json:"id,omitempty"`
	CLS           string `json:"cls,omitempty"`
	Text          string `json:"text,omitempty"`
	Icon          string `json:"iconCls,omitempty"`
	RecycleBin    string `json:"recycle_bin,omitempty"`
	RecycleFolder string `json:"recycle_folder,omitempty"`
	MaxItemLimit  int    `json:"max_item_limit,omitempty"`
	ItemCount     int    `json:"real_total,omitempty"`
}

type Privilege added in v1.2.0

type Privilege uint16

Privilege represents a linux file-system-level access privilege. It can be directly created as `Privilege(0644)` or from a string by using NewPrivilegeFromOctal().

const (
	Privilege_Invalid Privilege = 0
)

func NewPrivilegeFromOctal added in v1.2.0

func NewPrivilegeFromOctal(octalStr string) Privilege

NewPrivilegeFromOctal creates a new privilege by parsing a string like "644" or "0644". An empty or invalid string will return `Privilege_Invalid`.

func (Privilege) Bits added in v1.2.0

func (p Privilege) Bits() PrivilegeBits

Bits returns the bitwise representation of the privilege.

func (Privilege) String added in v1.2.0

func (p Privilege) String() string

String returns the octal representation of the privilege (without a leading zero), e.g. "644".

type PrivilegeBits added in v1.2.0

type PrivilegeBits struct {
	OwnerRead    bool
	OwnerWrite   bool
	OwnerExecute bool
	GroupRead    bool
	GroupWrite   bool
	GroupExecute bool
	OtherRead    bool
	OtherWrite   bool
	OtherExecute bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL