Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FTP/SFTP Service

Transfer files to and from remote servers using FTP, FTPS, or SFTP.

Configuration

FTP (Unencrypted)

{
  "service_type": "ftp",
  "config": {
    "host": "ftp.example.com",
    "port": 21,
    "username": "user",
    "password": "secret",
    "protocol": "ftp",
    "base_path": "/uploads",
    "passive_mode": true,
    "timeout_seconds": 30
  }
}

FTPS (FTP over TLS)

{
  "service_type": "ftp",
  "config": {
    "host": "ftp.example.com",
    "port": 21,
    "username": "user",
    "password": "secret",
    "protocol": "ftps",
    "passive_mode": true
  }
}

SFTP (SSH File Transfer)

{
  "service_type": "ftp",
  "config": {
    "host": "sftp.example.com",
    "port": 22,
    "username": "user",
    "password": "secret",
    "protocol": "sftp",
    "base_path": "/home/user/uploads"
  }
}

Or with SSH key authentication:

{
  "service_type": "ftp",
  "config": {
    "host": "sftp.example.com",
    "port": 22,
    "username": "user",
    "private_key_path": "/path/to/id_rsa",
    "protocol": "sftp"
  }
}

Configuration Options

FieldTypeDefaultDescription
hoststringrequiredFTP server hostname
portu1621/22Server port (21 for FTP/FTPS, 22 for SFTP)
usernamestringrequiredLogin username
passwordstringnullLogin password
private_key_pathstringnullPath to SSH private key (SFTP only)
protocolstring"ftp"Protocol: "ftp", "ftps", or "sftp"
base_pathstringnullDefault directory on server
passive_modebooltrueUse passive mode (FTP/FTPS only)
timeout_secondsu3230Connection timeout

Usage

Upload a File

#![allow(unused)]
fn main() {
use rust_edge_gateway_sdk::prelude::*;

fn handle(req: Request) -> Response {
    let ftp = FtpPool { pool_id: "uploads".to_string() };
    
    // Upload content
    let content = req.body.as_ref().unwrap();
    let result = ftp.put("/reports/daily.csv", content.as_bytes());
    
    match result {
        Ok(()) => Response::ok(json!({"uploaded": true})),
        Err(e) => Response::internal_error(e.to_string()),
    }
}
}

Download a File

#![allow(unused)]
fn main() {
fn handle(req: Request) -> Response {
    let ftp = FtpPool { pool_id: "files".to_string() };
    
    let filename = req.path_param("filename").unwrap();
    let path = format!("/data/{}", filename);
    
    match ftp.get(&path) {
        Ok(content) => Response::new(200)
            .with_header("Content-Type", "application/octet-stream")
            .with_body(content),
        Err(e) => Response::not_found(),
    }
}
}

List Directory

#![allow(unused)]
fn main() {
fn handle(req: Request) -> Response {
    let ftp = FtpPool { pool_id: "files".to_string() };
    
    match ftp.list("/reports") {
        Ok(files) => Response::ok(json!({"files": files})),
        Err(e) => Response::internal_error(e.to_string()),
    }
}
}

Use Cases

  • File uploads - Accept user uploads and store on FTP server
  • Report distribution - Upload generated reports to partner SFTP servers
  • Data import - Download files from vendor FTP for processing
  • Backup - Archive data to remote storage
  • Legacy integration - Connect to systems that only support FTP

Security Notes

  1. Prefer SFTP - Uses SSH encryption, most secure option
  2. Use FTPS if SFTP unavailable - TLS encryption for FTP
  3. Avoid plain FTP - Credentials sent in cleartext
  4. Use SSH keys - More secure than passwords for SFTP
  5. Restrict base_path - Limit access to specific directories