FTP
This cordova plugin is created to use ftp (client) in web/js.
Repo: https://github.com/xfally/cordova-plugin-ftp
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-ftp $ npm install --save @ionic-native/ftp@4
- Add this plugin to your app's module
Supported platforms
- Android
- iOS
Usage
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));
Instance Members
connect(hostname, username, password)
Connect to one ftp server.
Just need to init the connection once. If success, you can do any ftp actions later.
Param | Type | Details |
---|---|---|
hostname |
string
|
The ftp server url. Like ip without protocol prefix, e.g. "192.168.1.1". |
username |
string
|
The ftp login username. If it and |
password |
string
|
The ftp login password. If it and |
Returns: 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!
ls(path)
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 | Type | Details |
---|---|---|
path |
string
|
The path on the ftp server. e.g. "/adf/123/". |
Returns: Promise<any>
Returns a promise
mkdir(path)
Create one directory on the ftp server.
Param | Type | Details |
---|---|---|
path |
string
|
The path on the ftp server. e.g. "/adf/123/". |
Returns: Promise<any>
Returns a promise
rmdir(path)
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 | Type | Details |
---|---|---|
path |
string
|
The file (with full path) you want to delete. e.g. "/adf/123/newDir/myFile". |
Returns: Promise<any>
Returns a promise
rm(file)
Delete one file on the ftp server.
Param | Type | Details |
---|---|---|
file |
string
|
The file (with full path) you want to delete. e.g. "/adf/123/newDir/myFile". |
Returns: Promise<any>
Returns a promise
upload(localFile, remoteFile)
Upload one local file to the ftp server.
Param | Type | Details |
---|---|---|
localFile |
string
|
The file (with full path) you want to upload. e.g. "/local/path/to/localFile". |
remoteFile |
string
|
The file (with full path) you want to located on the ftp server. e.g. "/adf/123/newDir/remoteFile". |
Returns: Observable<any>
Returns an observable.
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.
download(localFile, remoteFile)
Download one remote file on the ftp server to local path.
Param | Type | Details |
---|---|---|
localFile |
string
|
The file (with full path) you want to upload. e.g. "/local/path/to/localFile". |
remoteFile |
string
|
The file (with full path) you want to located on the ftp server. e.g. "/adf/123/newDir/remoteFile". |
Returns: Observable<any>
Returns an observable.
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.
cancel()
Cancel all requests. Always success.
Returns: Promise<any>
Returns a promise
disconnect()
Disconnect from ftp server.
Returns: Promise<any>
Returns a promise