Skip to main content

Module ftp

Module ftp 

Source
Available on crate feature ftp only.
Expand description

§FTP Tasklet

This module provides tasklets for FTP file transfer operations (put and get). It’s designed to be similar to Spring Batch’s FTP capabilities for batch file transfers.

§Features

  • FTP PUT operations (upload files to FTP server)
  • FTP GET operations (download files from FTP server)
  • FTP PUT FOLDER operations (upload entire folder contents to FTP server)
  • FTP GET FOLDER operations (download entire folder contents from FTP server)
  • Support for both active and passive FTP modes
  • Configurable connection parameters
  • Proper error handling and logging
  • Builder pattern for easy configuration

§Memory Efficiency Features

Streaming Downloads (Implemented):

  • Both FtpGetTasklet and FtpGetFolderTasklet use retr() streaming method to download files directly from FTP server to local storage without loading entire files into memory
  • This approach is memory-efficient for files of any size, from small to very large
  • Uses proper error type conversion between std::io::Error and FtpError through the io_error_to_ftp_error helper function

Performance Benefits:

  • Constant memory usage regardless of file size
  • Improved performance for large file transfers
  • Reduced risk of out-of-memory errors when processing large files
  • Direct streaming from network to disk without intermediate buffering

§Examples

§FTP PUT Operation

use spring_batch_rs::core::step::{StepBuilder, StepExecution, Step};
use spring_batch_rs::tasklet::ftp::FtpPutTaskletBuilder;
use std::path::Path;

let ftp_put_tasklet = FtpPutTaskletBuilder::new()
    .host("ftp.example.com")
    .port(21)
    .username("user")
    .password("password")
    .local_file("./local_file.txt")
    .remote_file("/remote/path/file.txt")
    .passive_mode(true)
    .build()?;

let step = StepBuilder::new("ftp-upload")
    .tasklet(&ftp_put_tasklet)
    .build();

let mut step_execution = StepExecution::new("ftp-upload");
step.execute(&mut step_execution)?;

§FTP GET Operation (Memory-Efficient Streaming)

use spring_batch_rs::tasklet::ftp::FtpGetTaskletBuilder;

// This tasklet streams large files directly to disk without loading into memory
let ftp_get_tasklet = FtpGetTaskletBuilder::new()
    .host("ftp.example.com")
    .username("user")
    .password("password")
    .remote_file("/remote/path/large_file.zip")  // Works efficiently with any file size
    .local_file("./downloaded_large_file.zip")
    .build()?;

§FTPS (Secure FTP) Operations

use spring_batch_rs::tasklet::ftp::{FtpPutTaskletBuilder, FtpGetTaskletBuilder};

// Secure upload using FTPS (FTP over TLS)
let secure_upload = FtpPutTaskletBuilder::new()
    .host("secure-ftp.example.com")
    .port(990)  // Common FTPS port
    .username("user")
    .password("password")
    .local_file("./sensitive_data.txt")
    .remote_file("/secure/path/data.txt")
    .secure(true)  // Enable FTPS
    .build()?;

// Secure download using FTPS with streaming for memory efficiency
let secure_download = FtpGetTaskletBuilder::new()
    .host("secure-ftp.example.com")
    .port(990)
    .username("user")
    .password("password")
    .remote_file("/secure/path/confidential.zip")
    .local_file("./confidential.zip")
    .secure(true)  // Enable FTPS
    .build()?;

Structs§

FtpGetFolderTasklet
A tasklet for downloading entire folder contents from an FTP server.
FtpGetFolderTaskletBuilder
Builder for creating FtpGetFolderTasklet instances with a fluent interface.
FtpGetTasklet
A tasklet for downloading files from an FTP server.
FtpGetTaskletBuilder
Builder for creating FtpGetTasklet instances with a fluent interface.
FtpPutFolderTasklet
A tasklet for uploading entire folder contents to an FTP server.
FtpPutFolderTaskletBuilder
Builder for creating FtpPutFolderTasklet instances with a fluent interface.
FtpPutTasklet
A tasklet for uploading files to an FTP server.
FtpPutTaskletBuilder
Builder for creating FtpPutTasklet instances with a fluent interface.