mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-21 00:23:00 +08:00
feat(plugin): add FTP plugin (#1627)
This commit is contained in:
parent
ee59b55c29
commit
2d3add6507
133
src/@ionic-native/plugins/ftp/index.ts
Normal file
133
src/@ionic-native/plugins/ftp/index.ts
Normal file
@ -0,0 +1,133 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
|
||||
|
||||
/**
|
||||
* @name FTP
|
||||
* @description
|
||||
* This cordova plugin is created to use ftp (client) in web/js.
|
||||
*
|
||||
* @usage
|
||||
* ```typescript
|
||||
* import { FTP } from '@ionic-native/ftp';
|
||||
*
|
||||
*
|
||||
* constructor(private fTP: FTP) { }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
*
|
||||
* this.fTP.connect('ftp_host', 'ftp_user', 'ftp_password')
|
||||
* .then((res: any) => console.log('Login successful', res))
|
||||
* .catch((error: any) => console.error(error));
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'FTP',
|
||||
plugin: 'cordova-plugin-ftp',
|
||||
pluginRef: 'cordova.plugin.ftp',
|
||||
repo: 'https://github.com/xfally/cordova-plugin-ftp',
|
||||
platforms: ['Android', 'iOS']
|
||||
})
|
||||
@Injectable()
|
||||
export class FTP extends IonicNativePlugin {
|
||||
|
||||
/**
|
||||
* Connect to one ftp server.
|
||||
*
|
||||
* Just need to init the connection once. If success, you can do any ftp actions later.
|
||||
* @param hostname {string} The ftp server url. Like ip without protocol prefix, e.g. "192.168.1.1".
|
||||
* @param username {string} The ftp login username. If it and `password` are all blank/undefined, the default username "anonymous" is used.
|
||||
* @param password {string} The ftp login password. If it and `username` are all blank/undefined, the default password "anonymous@" is used.
|
||||
* @return {Promise<any>} The success callback. Notice: For iOS, if triggered, means `init` success, but NOT means the later action, e.g. `ls`... `download` will success!
|
||||
*/
|
||||
@Cordova()
|
||||
connect(hostname: string, username: string, password: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* List files (with info of `name`, `type`, `link`, `size`, `modifiedDate`) under one directory on the ftp server.
|
||||
* You can get one file's name using `fileList[x].name` (`x` is the location in array).
|
||||
*
|
||||
* Explain key:
|
||||
* - name: file name (utf-8).
|
||||
* - type: file type. number `0` means regular file, `1` means directory, `2` means symbolic link, `-1` means unknown type (maybe block dev, char dev...).
|
||||
* - link: if the file is a symbolic link, then this field store symbolic link information (utf-8), else it's a blank string.
|
||||
* - size: file size in bytes.
|
||||
* - modifiedDate: modified date of this file. date format is `yyyy-MM-dd HH:mm:ss zzz`, e.g "2015-12-01 20:45:00 GMT+8".
|
||||
*
|
||||
* @param path {string} The path on the ftp server. e.g. "/adf/123/".
|
||||
* @return {Promise<any>} Returns a promise
|
||||
*/
|
||||
@Cordova()
|
||||
ls(path: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Create one directory on the ftp server.
|
||||
*
|
||||
* @param path {string} The path on the ftp server. e.g. "/adf/123/".
|
||||
* @return {Promise<any>} Returns a promise
|
||||
*/
|
||||
@Cordova()
|
||||
mkdir(path: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Delete one directory on the ftp server.
|
||||
*
|
||||
* Tip: As many ftp server could not rm dir when it's not empty, so rm all files under the dir at first is recommended.
|
||||
*
|
||||
* @param path {string} The file (with full path) you want to delete. e.g. "/adf/123/newDir/myFile".
|
||||
* @return {Promise<any>} Returns a promise
|
||||
*/
|
||||
@Cordova()
|
||||
rmdir(path: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Delete one file on the ftp server.
|
||||
*
|
||||
* @param file {string} The file (with full path) you want to delete. e.g. "/adf/123/newDir/myFile".
|
||||
* @return {Promise<any>} Returns a promise
|
||||
*/
|
||||
@Cordova()
|
||||
rm(file: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Upload one local file to the ftp server.
|
||||
*
|
||||
* @param localFile {string} The file (with full path) you want to upload. e.g. "/local/path/to/localFile".
|
||||
* @param remoteFile {string} The file (with full path) you want to located on the ftp server. e.g. "/adf/123/newDir/remoteFile".
|
||||
* @return {Promise<any>} Returns a promise.
|
||||
* It will be triggered many times according the file's size.
|
||||
* The arg `0`, `0.1xx`, `0.2xx` ... `1` means the upload percent. When it reach `1`, means success.
|
||||
*/
|
||||
@Cordova()
|
||||
upload(localFile: string, remoteFile: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Download one remote file on the ftp server to local path.
|
||||
*
|
||||
* @param localFile {string} The file (with full path) you want to upload. e.g. "/local/path/to/localFile".
|
||||
* @param remoteFile {string} The file (with full path) you want to located on the ftp server. e.g. "/adf/123/newDir/remoteFile".
|
||||
* @return {Promise<any>} Returns a promise.
|
||||
* It will be triggered many times according the file's size.
|
||||
* The arg `0`, `0.1xx`, `0.2xx` ... `1` means the upload percent. When it reach `1`, means success.
|
||||
*/
|
||||
@Cordova()
|
||||
download(localFile: string, remoteFile: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Cancel all requests. Always success.
|
||||
*
|
||||
* @return {Promise<any>} Returns a promise
|
||||
*/
|
||||
@Cordova()
|
||||
cancel(): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Disconnect from ftp server.
|
||||
*
|
||||
* @return {Promise<any>} Returns a promise
|
||||
*/
|
||||
@Cordova()
|
||||
disconnect(): Promise<any> { return; }
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user