Skip to content

FileSystem FtpFileSystem

github-actions[bot] edited this page Dec 4, 2026 · 1 revision

FtpFileSystem

FtpFileSystem, in the Blueprint.FileSystem.Ftp namespace, stores files under an FTP account directory. Applications use the same relative paths for FTP operations and for the public URLs served by their web server or CDN.

Configure an FTP provider

Pass the FTP host, username, password, absolute directory within the FTP account, and public base URL to the constructor. The defaults are port 21 and explicit TLS. For a plain FTP server, pass useTls: false. The account needs permissions for the operations your application uses.

using Blueprint.FileSystem;
using Blueprint.FileSystem.Ftp;

string password = Environment.GetEnvironmentVariable("ASSETS_FTP_PASSWORD") ?? throw new InvalidOperationException("Set ASSETS_FTP_PASSWORD for this example.");
BlueprintFileSystem assets = new FtpFileSystem("ftp.example.com", "catalog", password, "/assets", new Uri("https://cdn.example.com/assets/"));

Here Products/Photos/1.png maps to /assets/Products/Photos/1.png on the FTP server. Configure the web server to serve that file at https://cdn.example.com/assets/Products/Photos/1.png.

Transfers and batches

A single-file read, write, move or delete opens one FTP control connection. For a nonempty WriteFiles, ReadFiles or DeleteFiles batch, the provider authenticates once and processes the names in order on that connection. FTP uses a separate data connection for each file transfer.

Operation FTP behavior
ReadFile(path) Opens one binary download (RETR) and returns a forward-only Stream. Dispose it to release the FTP session, including after a partial read.
ReadFiles(path, fileNames) Downloads each file once to temporary local storage. The session closes before the method returns a List<Stream> in file-name order. Dispose each stream to release its temporary storage. If a download fails, the provider closes the streams it already opened.
WriteFile(path, content) Sends one binary upload (STOR) directly to the final path in an existing directory, replacing existing contents if permitted. The provider reads from the current position of content, waits for the server's completion reply, and leaves the source stream open.
WriteFiles(path, streams, finalNames) Requires one final name per stream. Uploads streams[i] to finalNames[i] in order and confirms each upload before starting the next. The caller retains ownership of the streams.
MoveFile(sourcePath, destinationPath) Sends RNFR and RNTO on the same connection to move or rename the file. The destination directory must exist. The server determines whether an existing destination can be replaced.
DeleteFile(path) Sends DELE directly for the file. If the server rejects the deletion, the provider throws an IOException.
DeleteFiles(path, fileNames) Sends one DELE per name in list order. A server rejection stops the batch.

For batch operations, pass the directory as path and supply individual file names in the list. An interrupted upload can leave a partial file at its final name. If a write or delete batch fails, earlier uploads or deletions remain in effect.

Existence checks

Method FTP behavior
FileExists(path) Returns true when the FTP server reports a file at the relative path and false when it reports the file is absent.
DirectoryExists(path) Returns true when the FTP server reports a directory at the relative path and false when it reports the directory is absent.

Directories

Method FTP behavior
GetFiles(path) Lists the directory once and returns a List<string> of immediate file names. An empty directory yields an empty list.
GetDirectories(path) Lists the directory once and returns a List<string> of immediate subdirectory names. If there are no subdirectories, the list is empty.
CreateDirectory(path) Sends MKD directly. Its parent must exist, and the server may reject a directory that already exists.
DeleteDirectory(path, recursiveDelete = false) Sends RMD for an empty directory. With recursiveDelete: true, the provider lists and removes the contents before removing the directory itself.

Public URLs

Method Behavior
GetPublicUrl(path) Returns an absolute HTTP or HTTPS Uri under publicBaseURL, encoding each name in the relative path. This inherited method opens no FTP connection.

Related topics

BlueprintFileSystem API · LocalFileSystem · Class source · User manual

Clone this wiki locally