PHP Agent enables file operations over HTTP when SSH access is unavailable. Ideal for shared hosting environments.
sftp.php) deployed to web serverhttps://example.com/sftp.phpsftp.php...\\plugins\\wfx\\sftpplug\\sftp.php (build also copies it to build\\bin\\sftp.php)sftp.php to web-accessible locationhttps://example.com/sftp.phpThree configuration methods (in order of preference):
AGENT_PSK=your_secret_key_hereEnvironment keys checked:
TC_SFTP_AGENT_PSK, SFTP_AGENT_PSK, AGENT_PSK
const AGENT_PSK = 'your_secret_key_here';
const AGENT_PSK_SALT = 'random_salt'; const AGENT_PSK_SHA256 = 'sha256(salt:psk)';Allows upload-only deployment without knowing plain PSK
The password never travels. Every request except PROBE carries:
X-SFTP-TS: Unix time of the request
X-SFTP-NONCE: random, 8-128 characters [A-Za-z0-9._-], never reused
X-SFTP-CONTENT-SHA256: hex SHA-256 of the request body (of "" when there is none)
X-SFTP-SIGNATURE-V2: hex HMAC-SHA256(key, "TCSFTP-HMAC-V2" \n METHOD \n OPERATION \n
canonical query \n content SHA-256 \n timestamp \n nonce)
AGENT_PSK_SALT ":" password — exactly the value AGENT_PSK_SHA256 holds, so an agent that stores only the hash verifies signatures too. With a plain PSK (environment variable or AGENT_PSK) the agent derives the same key itself. PROBE tells the client the salt.path, to, cmd, offset, ...), and the body through its hash.The PSK in the clear (X-SFTP-AUTH) and the partial signature of plugins before 10.3.1 are refused unless const AGENT_ACCEPT_LEGACY_AUTH = true; is set in sftp.php — only while such a plugin still has to connect. A plugin from 10.3.1 on refuses an agent that does not sign and says so; it never falls back to sending the password.
The signing key is in sftp.php as the hash: keep the file readable by the web server only. Signing protects the password and every request on plain HTTP too, but not the files themselves — use HTTPS so that transfers stay private.
AGENT_ROOT; paths with .., and links pointing outside the root, are refusedSHELL_EXEC runs any command as the web server user, outside AGENT_ROOT too. Whoever holds the password has that access. Set const AGENT_ALLOW_SHELL = false; in sftp.php when the shell is not needed.
https://example.com/sftp.php https://example.com/path/to/sftp.php https://example.com/sftp.php?path=/subdir
https://example.com:8443/sftp.php
Can specify path in URL or via parameter:
https://example.com/sftp.php?path=files https://example.com/sftp.php?path=%2Fvar%2Fwww
Automatic on first connection:
GET https://example.com/sftp.php?op=PROBE
Response to an unsigned PROBE:
{
"ok": true,
"agent": { "name": "TC PHP Agent", "version": "1.1.0" },
"auth": { "scheme": "TCSFTP-HMAC-V2", "salt": "3f9c..." },
"capabilities": { "recommended_chunk_size": 1048576 }
}
Response to a signed PROBE:
{
"ok": true,
"agent": { "name": "TC PHP Agent", "version": "1.1.0" },
"capabilities": { "recommended_chunk_size": 1048576, "operations": [...], ... },
"runtime": { "php_version": "8.2", "sapi": "apache2handler" },
"ini": { "upload_max_filesize": "256M", ... }
}
capabilities.recommended_chunk_size from PROBE1..64 MB1 MB2 / 4 / 8 / 16 / 32 / 64 MB
GET https://example.com/sftp.php?op=LIST&path=/subdir
Response (JSON):
{
"ok": true,
"path": "subdir",
"items": [
{ "name": "file.txt", "is_dir": false, "size": 1234, "mtime": 1234567890, "perms": "0644" }
]
}
Response (Plain):
F\t1234\t1234567890\tbase64(filename)
D\t0\t1234567890\tbase64(dirname)
GET https://example.com/sftp.php?op=GET&path=file.txt&offset=0&length=1024 Headers: Content-Type: application/octet-stream Content-Length: 1024 X-SFTP-File-Size: 5000 X-SFTP-Offset: 0 Accept-Ranges: bytes
POST https://example.com/sftp.php?op=PUT&path=file.txt&offset=0
Headers:
Content-Type: multipart/form-data or raw POST data
X-SFTP-Content-SHA256: sha256hash (optional verification)
Response:
{
"ok": true,
"path": "file.txt",
"written": 1024,
"size": 5000,
"sha256": "abc123...",
"part": true
}
POST https://example.com/sftp.php?op=FINALIZE&path=file.txt&overwrite=1
Response:
{
"ok": true,
"path": "file.txt",
"size": 5000,
"finalized": true
}
POST https://example.com/sftp.php?op=DELETE&path=file.txt
Response:
{ "ok": true, "deleted": true, "path": "file.txt" }
POST https://example.com/sftp.php?op=MKDIR&path=newdir&recursive=1&mode=0775
Response:
{ "ok": true, "created": true, "path": "newdir" }
mode is three octal digits, optionally with a leading zero; anything else is refused with INVALID_MODE.
POST https://example.com/sftp.php?op=RMDIR&path=olddir&recursive=0
Response:
{ "ok": true, "removed": true, "path": "olddir", "recursive": false }
The agent root is refused with ROOT_PROTECTED. A link to a directory is removed as a link; the directory it points to stays. The same holds for DELETE and RENAME: they act on the link, not on its target.
POST https://example.com/sftp.php?op=RENAME&from=old.txt&to=new.txt&overwrite=1
Response:
{ "ok": true, "renamed": true, "from": "old.txt", "to": "new.txt" }
GET https://example.com/sftp.php?op=HASH&path=file.txt&algo=sha256
Response:
{ "ok": true, "path": "file.txt", "algo": "sha256", "hash": "abc123..." }
GET https://example.com/sftp.php?op=TAR_STREAM&path=/subdir Response: raw ustar TAR stream (application/x-tar)
The server streams the entire directory tree as a ustar TAR archive. The plugin parses the stream on the fly: directories are created immediately, files are written as their data arrives. GNU long-name extension records (././@LongLink, typeflag L) are handled for paths longer than 99 characters. The stream ends with two consecutive 512-byte zero blocks (standard TAR end-of-archive marker). Used when downloading an entire directory.
Enabled when the TAR stream checkbox is checked and a single directory is being downloaded.
POST https://example.com/sftp.php?op=TAR_PACK Content-Type: text/plain relative/path/file1.txt relative/path/file2.bin subdir/file3.jpg Response: raw ustar TAR stream (application/x-tar)
The plugin sends a list of relative remote paths (one per line, newline-separated) in the POST body. The server packs exactly those paths into a ustar TAR and streams the result directly to the response — no temporary file, no memory buffer, no Content-Length header. The plugin parses the TAR on the fly and writes each file to the local destination as it arrives.
Directories listed are included as directory entries (typeflag 5). Files larger than 8 589 934 591 bytes are skipped (POSIX ustar octal limit) without corrupting the rest of the archive. GNU LongLink is used for paths over 99 characters.
Enabled when the TAR stream checkbox is checked and multiple files are selected for download (TC GET_MULTI batch operation).
POST https://example.com/sftp.php?op=TAR_EXTRACT&path=/subdir
Content-Type: application/x-tar
Content-Length: <exact 64-bit size>
[ustar TAR body]
Response:
{ "ok": true, "extracted": N }
The plugin packs all queued files into a single ustar TAR stream (with GNU long-name entries where needed) and sends it in one POST. The server extracts it under path. Files are queued during the TC copy operation and sent all at once when TC signals end-of-batch via FsStatusInfo. Content-Length is sent as a proper 64-bit value — no overflow for archives exceeding 4 GB.
Enabled when the TAR stream checkbox is checked and files are being uploaded.
POST https://example.com/sftp.php?op=SHELL_EXEC&cmd=ls+-la&cwd=/var/www
Response:
{
"ok": true,
"cwd": ".",
"cwd_abs": "/var/www",
"method": "shell_exec",
"exit_code": 0,
"stdout_b64": "base64_encoded_output",
"stderr_b64": "base64_encoded_errors"
}
With AGENT_ALLOW_SHELL = false the agent answers HTTP 403 SHELL_DISABLED.
Pseudo-terminal interface for command execution:
upload_max_filesize: Maximum single uploadpost_max_size: Maximum POST datamax_execution_time: Script timeoutmemory_limit: Memory per requestAGENT_NAME = 'TC PHP Agent' AGENT_VERSION = '1.0.2' AGENT_PSK = 'CHANGE_ME_TO_LONG_RANDOM_SECRET' AGENT_PSK_SALT = '' AGENT_PSK_SHA256 = '' AGENT_ROOT = __DIR__ (or custom path) AGENT_ALLOW_SHELL = true (false refuses SHELL_EXEC) AGENT_NONCE_TTL = 300 AGENT_DEFAULT_CHUNK = 262144 AGENT_MAX_LIST_ITEMS = 20000