filezilla-js
v0.0.9
Published
Can be used to read the FileZilla XML config located in AppData
Downloads
8
Readme
FileZillaJS - Interface for reading sitemanager.xml into js objects
Examples
Instantiating siteManager
The SiteManager
class can be instantiated in two different ways.
Either using the default XML file (found using your current environment variables):
import {getDefaultSiteManager} from "filezilla-js";
const siteManager = getDefaultSiteManager();
Or by using a specific sitemanager.xml
path by using getSiteManager
instead of getDefaultSiteManager
:
import {getSiteManager} from "filezilla-js";
// Point at the custom sitemanager.xml file
const siteManager = getSiteManager(path.join(__dirname, 'fixtures/sitemanager.xml'));
Fetching servers
Getting a single server by root path
Use siteManager.getServerByPath(path)
to get a single Server
object or NULL
if it wasn't found:
import {getDefaultSiteManager} from "filezilla-js";
const siteManager = getDefaultSiteManager();
// Get server by path "SFTP (root location)" (a server with that name, in the root of the sitemanager.xml)
const server = siteManager.getServerByPath(`SFTP (root location)`);
if (!server) {
console.error(`Error: Could not find server by path ${serverPath}`);
} else {
console.log(`${serverPath} (host: ${server.properties.host}:${server.properties.port})`);
}
Getting a single server by sub paths
Use siteManager.getServerByPath(path)
to get a single Server
object or NULL
if it wasn't found:
import {getDefaultSiteManager} from "filezilla-js";
const siteManager = getDefaultSiteManager();
// Get server by path "Rebex/SFTP" (a server with that the name "SFTP" in the "Rebex" folder)
const server = siteManager.getServerByPath(`Rebex/SFTP`);
if (!server) {
console.error(`Error: Could not find server by path ${serverPath}`);
} else {
console.log(`${serverPath} (host: ${server.properties.host}:${server.properties.port})`);
}
Getting all servers in an array
Use siteManager.getServers()
to get a list of Server
objects:
import {getDefaultSiteManager} from "filezilla-js";
const siteManager = getDefaultSiteManager();
const servers = siteManager.getServers();
for (let server of servers) {
console.log(`${server.path} (host: ${server.properties.host}:${server.properties.port})`);
}
Classes
Server
The main object returned from siteManager.getServer
is a Server
. It has the following properties:
path: string;
Properties
| Property | Property type | Description |
|------------|------------------|--------------------------------------------------------|
| path | string | The path of the server (eg. Rebex/SFTP
) |
| properties | ServerProperties | The raw properties of the FileZilla server (see below) |
Methods
Server.getRemoteDirectory(defaultRemoteDirectory:string = '')
:
Gets a human readable path (instead of the raw FileZilla path).
Example:
<RemoteDir>1 0 3 pub 7 example</RemoteDir>
^ ^ ^ ^ ^ ^
| | | | | |
| | | | | \-- The name of the sub folder
| | | | \-- The length of the sub folder ("example".length)
| | | \-- The name of the main folder
| | \-- The length of the main folder ("pub".length)
| \-- The length of the prefix
\-- The ServerType (see the definition)
In the instance above, the output of Server.getRemoteDirectory()
would be /pub/example
Definitions
ServerProperties
| Property | Property type | Description | |----------------------------|-----------------|--------------------------------------------------------------------------------| | host | string | The server host | | port | number | The server port | | protocol | ServerProtocol | The server protocol (ServerProtocol) | | type | ServerType | The server type (ServerType) | | user | string | The server username | | password | string | The server password | | keyFile | string | The path to the server key file | | logonType | LogonType | The server logon type (LogonType) | | timezoneOffset | number | The timezone offset | | passiveMode | PasvMode | The passive mode for this server (PassiveMode - only relevant for FTP servers) | | maximumMultipleConnections | number | The maximum concurrent connections to the server - 0 means no limit | | encodingType | CharsetEncoding | The server encoding type (CharsetEncoding) | | bypassProxy | boolean | Whether or not to bypass the proxy | | name | string | The server name in FileZilla | | comments | string | The server comments | | localDirectory | string | The initial local directory | | remoteDirectory | string | The initial remote directory (raw) | | synchronizedBrowsing | boolean | Whether or not to use synchronized browsing | | directoryComparison | boolean | Whether or not to use directory comparison |
Enums
Note: A lot of these enums can be found in the Filezilla sourcecode's server.h
file
CharsetEncoding
| Enum | Value | Description | |-----------------|-------|-------------| | ENCODING_AUTO | 0 | | | ENCODING_UTF8 | 1 | | | ENCODING_CUSTOM | 2 | |
LogonType
| Enum | Value | Description | |-------------|-------|---------------------------------------------------------------------------------| | ANONYMOUS | 0 | | | NORMAL | 1 | | | ASK | 2 | ask should not be sent to the engine, it's intended to be used by the interface | | INTERACTIVE | 3 | | | ACCOUNT | 4 | | | KEY | 5 | | | PROFILE | 6 | | | COUNT | 7 | |
PasvMode
| Enum | Value | Description | |--------------|--------------|-------------| | MODE_DEFAULT | MODE_DEFAULT | | | MODE_ACTIVE | MODE_ACTIVE | | | MODE_PASSIVE | MODE_PASSIVE | |
ServerFormat
| Enum | Value | Description | |-----------------------------|-------|-------------| | HOST_ONLY | 0 | | | WITH_OPTIONAL_PORT | 1 | | | WITH_USER_AND_OPTIONAL_PORT | 2 | | | URL | 3 | | | URL_WITH_PASSWORD | 4 | |
ServerProtocol
| Enum | Value | Description | |-----------------|-------|--------------------------------| | UNKNOWN | -1 | | | FTP | 0 | FTP, attempts AUTH TLS | | SFTP | 1 | | | HTTP | 2 | | | FTPS | 3 | Implicit SSL | | FTPES | 4 | Explicit SSL | | HTTPS | 5 | | | INSECURE_FTP | 6 | Insecure, as the name suggests | | S3 | 7 | Amazon S3 or compatible | | STORJ | 8 | | | WEBDAV | 9 | | | AZURE_FILE | 10 | | | AZURE_BLOB | 11 | | | SWIFT | 12 | | | GOOGLE_CLOUD | 13 | | | GOOGLE_DRIVE | 14 | | | DROPBOX | 15 | | | ONEDRIVE | 16 | | | B2 | 17 | | | BOX | 18 | | | INSECURE_WEBDAV | 19 | | | RACKSPACE | 20 | | | STORJ_GRANT | 21 | |
ServerType
| Enum | Value | Description | |-----------------|-------|---------------------------------------| | DEFAULT | 0 | | | UNIX | 1 | | | VMS | 2 | | | DOS | 3 | Backslashes as preferred separator | | MVS | 4 | | | VXWORKS | 5 | | | ZVM | 6 | | | HPNONSTOP | 7 | | | DOS_VIRTUAL | 8 | | | CYGWIN | 9 | | | DOS_FWD_SLASHES | 10 | Forwardslashes as preferred separator | | SERVERTYPE_MAX | 11 | |