๐Ÿ”ท Core

bx-ftp

Use this skill when working with FTP, FTPS, or SFTP operations in BoxLang: connecting to servers, uploading/downloading files, managing remote directories, listing contents, SSH key authentication, named connection pooling, and using the bx:ftp component.

$ npx skills add ortus-boxlang/skills/boxlang-modules/bx-ftp
$ coldbox ai skills install ortus-boxlang/skills/boxlang-modules/bx-ftp
๐Ÿ”— https://skills.boxlang.io/skills/raw/ortus-boxlang/skills/boxlang-modules~bx-ftp

bx-ftp: FTP / SFTP Module

BoxLang is the AI-native software productivity platform for building, modernizing and running applications, with developers and AI agents working together.

Installation

# OS runtime
install-bx-module bx-ftp
# CommandBox web server
box install bx-ftp

Common bx:ftp Actions

ActionDescription
openOpen a connection (creates named connection)
closeClose a named connection
putFileUpload a local file to the server
getFileDownload a file from the server
listDirList directory contents
createDirCreate a remote directory
deleteDirDelete a remote directory
removeDelete a remote file
renameRename/move a remote file or directory
changeDirChange the current remote directory
getCurrentDirGet the current remote working directory
existsDirCheck if a remote directory exists
existsFileCheck if a remote file exists

FTP Connection

// Open a named FTP connection
bx:ftp
    action="open"
    connection="myFTP"
    server="ftp.example.com"
    port=21
    username="user"
    password="secret"
    passive=true

// Upload a file
bx:ftp
    action="putFile"
    connection="myFTP"
    localFile="/local/path/report.pdf"
    remoteFile="/uploads/report.pdf"
    result="ftpResult"

if ( ftpResult.succeeded ) {
    println( "Uploaded successfully" )
}

// Download a file
bx:ftp
    action="getFile"
    connection="myFTP"
    remoteFile="/uploads/report.pdf"
    localFile="/local/downloads/report.pdf"

// List directory
bx:ftp
    action="listDir"
    connection="myFTP"
    directory="/uploads"
    result="dirList"
    returnType="query"   // "query" (default) or "array"

for ( row in dirList ) {
    println( "#row.name# (#row.type#) - #row.size# bytes" )
}

// Close connection
bx:ftp
    action="close"
    connection="myFTP"

SFTP with Username/Password

bx:ftp
    action="open"
    connection="mySFTP"
    server="sftp.example.com"
    port=22
    username="sftpuser"
    password="secret"
    protocol="sftp"

SFTP with SSH Key Authentication

bx:ftp
    action="open"
    connection="secureSFTP"
    server="sftp.example.com"
    port=22
    username="deployuser"
    privateKeyFile="/home/app/.ssh/id_rsa"
    privateKeyPassphrase=""     // Optional โ€” leave empty if key has no passphrase
    protocol="sftp"

FTPS (FTP over SSL/TLS)

bx:ftp
    action="open"
    connection="secureFTP"
    server="ftp.example.com"
    port=990
    username="user"
    password="secret"
    secure=true     // Enable FTPS
    passive=true

Directory Operations

// Create a directory
bx:ftp action="createDir" connection="myFTP" directory="/uploads/2026"

// Check if directory exists
bx:ftp action="existsDir" connection="myFTP" directory="/uploads/2026" result="exists"
if ( !exists.value ) {
    bx:ftp action="createDir" connection="myFTP" directory="/uploads/2026"
}

// Delete a directory
bx:ftp action="deleteDir" connection="myFTP" directory="/uploads/old"

Result Struct

Every action populates a result struct with:

KeyDescription
succeededBoolean โ€” operation succeeded
errorCodeFTP error code on failure
errorTextError message on failure
returnValueAction-specific return (e.g., current directory)

Common Pitfalls

  • โœ… Always close connections with action="close" in a finally block
  • โŒ Don't mix connection protocols โ€” passive=true only applies to FTP, not SFTP
  • โœ… Use named connections (connection="myFTP") across multiple operations for efficiency
  • โŒ Hardcoding credentials โ€” read them from environment variables or config files
  • โœ… Check result.succeeded before assuming an operation worked