Operations reference
All five remote-client objects (SftpClient, FtpsClient, S3Client, AzureClient, GCSClient) expose an identical set of methods. The same script logic works regardless of the underlying protocol (only the constructor and connection fields change).
Connection lifecycle
Connect()
function Connect(): bool;Establishes the connection to the remote system. Must be called before any other method. Returns true on success, false on failure (errors are written to the script log).
Close()
function Close(): bool;Closes the connection and releases all associated resources. Returns true on success.
Always call Close() when you are done, even if a transfer fails:
if (cli.Connect()) {
cli.Upload("/outbox/*.xml", "/remote/inbox");
cli.Close();
}Directory operations
ListDir(dir, types)
function ListDir(dir: string, types: int): DirListItem[];Returns a flat (non-recursive) listing of dir.
types constant | Value | Returns |
|---|---|---|
LIST_ALL | 0 | All entries (files and directories) |
LIST_FILES | 1 | Files only |
LIST_DIRS | 2 | Directories only |
ListDirR(dir, types)
function ListDirR(dir: string, types: int): DirListItem[];Recursive version of ListDir.
ListFiles(dir, mask)
function ListFiles(dir: string, mask: string): DirListItem[];Returns files inside dir whose names match the glob mask (e.g. "*.csv").
ListFilesR(dir, mask)
function ListFilesR(dir: string, mask: string): DirListItem[];Recursive version of ListFiles.
MakeDir(dir)
function MakeDir(dir: string): bool;Creates dir (and any missing parent directories where the protocol supports it). Returns true on success.
RenDir(what, toWhere)
function RenDir(what: string, toWhere: string): bool;Renames or moves a directory. Returns true on success.
NOTE
For object-storage backends (S3, Azure, GCS) this requires a copy-then-delete cycle because those services do not support atomic server-side renames.
DelDir(dir)
function DelDir(dir: string): bool;Deletes an empty directory. Returns true on success.
DelTree(dir)
function DelTree(dir: string): bool;Recursively deletes dir and all its contents. Returns true on success.
File operations
Stat(obj)
function Stat(obj: string): DirListItem | null;Returns metadata for the remote object obj, or null if it does not exist or the call fails.
var info = cli.Stat("/remote/report.csv");
if (info != null) {
Log("Size: " + info.Size + " Modified: " + info.TimeStamp);
} else {
Log("File not found");
}Rename(what, toWhere)
function Rename(what: string, toWhere: string): bool;Renames or moves a single file. Returns true on success.
Delete(what)
function Delete(what: string): bool;Deletes a single file. Returns true on success.
Transfers
All transfer methods accept a glob pattern in the what argument (e.g. "/local/dir/*.csv").
Transfer behaviour (overwrite policy, temp-name handling, OTFE, etc.) is controlled via ClientOptions.
Upload(what, toWhere)
function Upload(what: string, toWhere: string): bool;Uploads all files matching the glob what into the remote directory toWhere. Returns true if every file transferred successfully.
UploadR(what, toWhere)
function UploadR(what: string, toWhere: string): bool;Recursive version of Upload (descends into subdirectories).
UploadWithPath(what, toWhere, skip)
function UploadWithPath(what: string, toWhere: string, skip: int): bool;Like Upload, but skips skip leading path components from the source path when computing the remote destination path. Useful for replicating a partial directory tree without duplicating the full local prefix.
// Local file: /data/reports/2026/q1/summary.csv
// skip=2 strips "/data/reports" => remote path becomes /inbox/2026/q1/summary.csv
cli.UploadWithPath("/data/reports/**/*.csv", "/inbox", 2);UploadWithPathR(what, toWhere, skip)
function UploadWithPathR(what: string, toWhere: string, skip: int): bool;Recursive version of UploadWithPath.
Download(what, toWhere)
function Download(what: string, toWhere: string): bool;Downloads all files matching the glob what from the remote system into the local directory toWhere. Returns true if every file transferred successfully.
DownloadR(what, toWhere)
function DownloadR(what: string, toWhere: string): bool;Recursive version of Download.
DownloadWithPath(what, toWhere, skip)
function DownloadWithPath(what: string, toWhere: string, skip: int): bool;Like Download, but skips skip leading path components from the remote path when computing the local destination path.
DownloadWithPathR(what, toWhere, skip)
function DownloadWithPathR(what: string, toWhere: string, skip: int): bool;Recursive version of DownloadWithPath.
The DirListItem type
Directory listing and stat operations return DirListItem objects:
| Field | Type | Description |
|---|---|---|
Name | string | File or directory name (not the full path) |
Type | string | "FILE" or "DIR" |
Size | number | Size in bytes (0 for directories) |
TimeStamp | Date | Modification time as a JavaScript Date |
Full example
The following example uses an SFTP client with OTFE enabled and move semantics (delete after upload). Swap the constructor and connection fields to use any other protocol with no other changes.
var cli = new SftpClient();
cli.Host = "sftp.example.com:22";
cli.User = "alice";
cli.Pass = GetSecret("sftp-pass");
cli.HostKeySHA256 = "SHA256:AAAA...";
cli.Options.UploadPolicy = AlwaysOverwrite;
cli.Options.DeleteSourceAfterUpload = true; // move semantics: remove after upload
cli.Options.OTFE = true;
cli.Options.OTFEKey = GetSecret("transfer-encryption-key");
if (!cli.Connect()) {
Log("ERROR: could not connect to SFTP server");
} else {
var ok = cli.Upload("/outbox/*.xml", "/remote/inbox");
if (ok) {
Log("All files uploaded successfully");
} else {
Log("One or more files failed to upload");
}
cli.Close();
}