FTP

Improve this doc

This cordova plugin is created to use ftp (client) in web/js.

Repo: https://github.com/xfally/cordova-plugin-ftp

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-ftp
    $ npm install --save @ionic-native/ftp
    
  2. Add this plugin to your app's module

Supported platforms

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 are all blank/undefined, the default username "anonymous" is used.

password string

The ftp login password. If it and username are all blank/undefined, the default password "[email protected]" is used.

Returns: Promise<any> The success callback. Notice: For iOS, if triggered, means init success, but NOT means the later action, e.g. lsdownload 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:

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.2xx1 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.2xx1 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

API

Native

General