This object supports the client side of the sftp protocol, version 3, and implements an interface similar to the usual sftp command line client.

1 SftpClient

SFTP Object can be created invoking a new Constructor. Parameters expected are: hostname, port, username and password.

    var sftpconn = new, 22, 'informix','******');
Return Method Description
void disconnect() Disconnects from server
boolean exists(String name) Returns true if file name exists
void cd(String name) Changes working directory
void rm(String name) Deletes file
void rmdir(String name) Deletes empty directory
ArrayList<String> list(String pattern) Returns an array of files or folder names. You can get only a subset of files applying a pattern. You can use * as a replacement for any number of characters.
ArrayList<LsEntry> listFiles(String pattern) Return an array of LsEntry objects
void mkdir(String name) Creates a new directory with name passed as parameter
void put(String name, Object data) Sends the content of data and creates a new file remotely with this content. data can be a Blob, file, byte[], etc.
String pwd() Returns the current working directory
void rename(String src, String dst) Renames a file in server.
byte[] getBytes(String name) gets content of remote file in server with name passed as parameter.
Blob getBlob(String name) gets content of remote file and returns a Blob. Internal blob name are set from remote file name passed as parameter.

2 SFTP Usage


2.1 Basic example


    var sftpcon = new'dbsrv4', 22, 'informix','*****');"/tmp");
    if (!sftpcon.exists("TestFolder")) {
    sftpcon.put("RedSprites_Broady_960.jpg", new"").getBytes());

    return sftpcon.getBlob("RedSprites_Broady_960.jpg");

2.2 Advanced example

This advanced example, shows how an almost real example, creating folders, sending files, procesing directory or file lists and moving processed files to other directory.

    var sftpcon = new'dbsrv4', 22, 'informix','*****');

    if (!sftpcon.exists("/tmp/TestFolder")) {
        console.log("TestFolder doesn't exists. Creating...");

    sftpcon.put("RedSprites_Broady_960.jpg", new"").getBytes());
    sftpcon.put("M82Magnet_SOFIA_960.jpg", new"").getBytes());
    sftpcon.put("moonrisemk_connelley_960.jpg", new"").getBytes());
    sftpcon.put("M78_RGBwright1024.jpg", new"").getBytes());

    for each (var f of sftpcon.listFiles("/tmp/TestFolder/M*.jpg")) {
        console.log(f.getFilename() + " = " + f.getLongname() + "  Attr:" + f.getAttrs());
        sftpcon.rename(f.getFilename(), "PROCESSED/" + f.getFilename());

    return sftpcon.getBlob("/tmp/TestFolder/PROCESSED/M78_RGBwright1024.jpg");
[[M78_RGBwright1024.jpg, M82Magnet_SOFIA_960.jpg]]
[[moonrisemk_connelley_960.jpg, PROCESSED, ., M78_RGBwright1024.jpg, .., RedSprites_Broady_960.jpg, M82Magnet_SOFIA_960.jpg]]
[[moonrisemk_connelley_960.jpg, M78_RGBwright1024.jpg, RedSprites_Broady_960.jpg, M82Magnet_SOFIA_960.jpg]]
M78_RGBwright1024.jpg = -rw-rw-r--    1 informix informix   319827 Mar 12 17:38 M78_RGBwright1024.jpgAttr:-rw-rw-r-- 1000 1000 319827 Tue Mar 12 17:38:15 CET 2019
M82Magnet_SOFIA_960.jpg = -rw-rw-r--    1 informix informix    34520 Mar 12 17:38 M82Magnet_SOFIA_960.jpgAttr:-rw-rw-r-- 1000 1000 34520 Tue Mar 12 17:38:11 CET 2019