qie.readSFTPFile¶
Signature: qie.readSFTPFile(host, port, path, deleteFile, archivePath, binary, passive, ftpParameters, userName, password, timeout, sshKeyName*)
Returns: XML Message fileContentXml - an XML message containing the base64 encoded content of the file and the meta-data
Reads one file from the specified path.
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 read file from | |
| Boolean | deleteFile | if 'deleteFile' is true and 'archivePath' is null or blank, then the file will be deleted after it is downloaded | |
| String | archivePath | move file to 'archivePath' once it has been read. Leave this blank or null to use the 'deleteFile' option. | |
| 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 | |
| Integer | timeout | time in milliseconds to wait for connection before error | |
| String | sshKeyName* | (optional) the name of the ssh key stored as a private certificate key | null |
Example¶
// OPTIONAL SETUP:
// Create a file on the SFTP server so there is something to read.
// Ignore errors if the file already exists.
try {
qie.writeSFTPFile(
'sftp.example.com', // host: SFTP server hostname
22, // port: SFTP port
'theirs.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
'More data to go in theirs.txt.' // file contents
);
} catch (error) {
qie.warn(error); // Expected if file already exists
}
// READ FILE:
// Read a file from the SFTP server and archive it after reading.
var xmlResponse = qie.readSFTPFile(
'sftp.example.com', // host: SFTP server hostname
22, // port: SFTP port
'theirs.txt', // path: remote file path
true, // deleteFile: delete if archivePath is null/blank
'/archivePath/', // archivePath: move file here after reading
false, // binary: transfer mode
true, // passive: passive mode
'', // ftpParameters: additional Camel params
'interfaceUser', // userName: login username
'yourPassword', // password: login password
5000 // timeout: milliseconds to wait for connection
);
// The returned XML contains file metadata and base64-encoded file contents.
var encodedBytes = xmlResponse.getNode('/ftpFile/encodedBytes');
var fileContents = qie.base64Decode(encodedBytes);