Skip to content

qie.listSFTPEndpoint

Signature: qie.listSFTPEndpoint(host, port, path, binary, passive, ftpParameters, userName, password, sshKeyName*)

Returns: String[] fileNames - the array of leaf file names found (not full paths)

Returns an array of leaf file names (not full paths) found in the path specified. To read a returned file with qie.readSFTPFile(...), create a full path by joining the source folder with the file name.

Note

QIE uses version 4.22.0 of Apache Camel. (See this article for available parameters).

Parameters

Type Name Description Default
String host hostname or ip address for the ftp server
Integer port the port number to use
String path file path to list files
Boolean binary transfer data using binary protocol
Boolean passive use passive transfer mode (usually true)
String ftpParameters additional custom camel ftp parameters to be used by this connection. (Format: {key}={value}\n{key2}={value2}...)
String userName username to use for this connection
String password password to use for this connection
String sshKeyName* (optional) the name of the ssh key stored as a private certificate key null

Example

// OPTIONAL SETUP:
// Create a couple of files on the SFTP server so there is something to list.
// Ignore errors if the files already exist.

try {
    qie.writeSFTPFile(
        'sftp.example.com',                    // host: SFTP server hostname
        22,                                    // port: SFTP port
        'mine.txt',                            // path: remote file path
        false,                                 // binary: transfer mode
        true,                                  // passive: passive mode
        '',                                    // ftpParameters: additional Camel params
        'interfaceUser',                       // userName: login username
        'yourPassword',                        // password: login password
        'Here is some data to go in mine.txt.' // file contents
    );
} catch (error) {
    qie.warn(error); // Expected if file already exists
}

try {
    qie.writeSFTPFile(
        'sftp.example.com', // host
        22,                 // port
        'theirs.txt',       // path
        false,              // binary
        true,               // passive
        '',                 // ftpParameters
        'interfaceUser',    // userName
        'yourPassword',     // password
        'More data to go in theirs.txt.'
    );
} catch (error) {
    qie.warn(error);
}

// LIST FILES:
// Retrieve all file names in the remote directory using a wildcard path.

var filesFound = qie.listSFTPEndpoint(
    'sftp.example.com', // host: SFTP server hostname
    22,                 // port: SFTP port
    '*',                // path: wildcard to match all files
    false,              // binary: transfer mode
    true,               // passive: passive mode
    '',                 // ftpParameters: additional Camel params
    'interfaceUser',    // userName: login username
    'yourPassword'      // password: login password
);

if (filesFound.length > 0) {
    for (var i = 0; i < filesFound.length; i++) {
        qie.debug("Found file: " + filesFound[i]);
    }
} else {
    qie.debug("No files found on the SFTP server.");
}