Example: Ftp Download ​
Demonstrates ftpDownload.zig using the canonical HTTPX API.
Complete Example ​
zig
const std = @import("std");
const httpx = @import("httpx");
pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const io = std.Io.Threaded.global_single_threaded.io();
std.debug.print("==> Downloading file over FTP with progress and verification...\n", .{});
const res = httpx.client.download.ftpDownload(io, allocator, .{
.host = "127.0.0.1",
.port = 21,
.user = "anonymous",
.password = "anonymous@",
.remotePath = "/pub/archive.tar.gz",
.destinationPath = "downloads/archive.tar.gz",
.progress = .auto,
.verify = .{
.minSize = 10,
},
}) catch |err| {
std.debug.print("FTP download handled: {s}\n", .{@errorName(err)});
return;
};
std.debug.print("FTP download finished: {s} ({d} bytes)\n", .{ res.destination, res.downloadedBytes });
}Expected Output ​
text
==> Downloading file over FTP with progress and verification...
FTP download finished: downloads/archive.tar.gz (12345 bytes)Destinations, byte counts, and file sizes vary with the remote file; only the line format above is stable.
How to Run ​
bash
zig build run-ftp-download