In this page
GreyCat FTP Library
@library("ftp", "0.0.0");
FTP/FTPS client for GreyCat. Transfer files to and from remote servers using standard FTP or encrypted FTPS protocols.
Quick Start
// Connect to an FTP server
var ftp = Ftp {
url: "ftp://ftp.example.com",
credentials: "username:password",
};
// List remote directory
var entries = ftp.list("data/");
for (i, entry in entries) {
info("${entry.name} - ${entry.size} bytes (dir: ${entry.is_dir})");
}
// Download a file
ftp.get("data/report.csv", "/local/path/report.csv");
// Upload a file
ftp.put("/local/path/output.json", "uploads/output.json");
// Delete a remote file
ftp.delete("uploads/old_file.txt");
Supported Protocols
| Scheme | Description |
|---|---|
ftp:// |
Standard FTP (unencrypted) |
ftps:// |
FTP over SSL/TLS (encrypted) |
API Reference
Ftp
FTP/FTPS client for file transfer operations.
Constructor:
| Field | Type | Description |
|---|---|---|
url |
String |
Base URL with protocol scheme (e.g., "ftp://host", "ftps://host:990") |
credentials |
String? |
Login as "username:password". Omit for anonymous access |
timeout |
duration? |
Connection timeout. Defaults to 30s |
// Authenticated FTP
var ftp = Ftp { url: "ftp://ftp.example.com", credentials: "user:pass" };
// FTPS with custom port and timeout
var ftps = Ftp { url: "ftps://secure.example.com:990", credentials: "user:pass", timeout: 60_s };
// Anonymous FTP
var anon = Ftp { url: "ftp://ftp.gnu.org/gnu" };
Methods:
| Method | Returns | Description |
|---|---|---|
get(remote, local) |
void |
Download a remote file to a local path |
put(local, remote) |
void |
Upload a local file to a remote path |
list(dirpath) |
Array<FtpEntry> |
List files and directories at a remote path |
delete(filepath) |
void |
Delete a file on the remote server |
FtpEntry
Represents a file or directory entry returned by list().
| Field | Type | Description |
|---|---|---|
name |
String |
File or directory name |
is_dir |
bool |
true if directory, false if file |
size |
int |
Size in bytes |
modify |
String |
Last modification time in RFC 3659 format (YYYYMMDDhhmmss, UTC) |
Examples
Sync Remote Directory to Local
var ftp = Ftp { url: "ftp://ftp.example.com", credentials: "user:pass" };
var entries = ftp.list("exports/");
for (i, entry in entries) {
if (!entry.is_dir) {
ftp.get("exports/${entry.name}", "/local/exports/${entry.name}");
info("Downloaded: ${entry.name} (${entry.size} bytes, modified: ${entry.modify})");
}
}
Upload and Cleanup
var ftp = Ftp { url: "ftps://secure.example.com", credentials: "user:pass" };
ftp.put("/local/data/batch_001.csv", "inbox/batch_001.csv");
info("Upload complete");
// Clean up old files
ftp.delete("inbox/batch_000.csv");