TFtpServer
Source: source/classes/tftpserv.prg
Standalone class
TFtpServer implements a basic FTP server using TSocket. It listens on port 21 and handles standard FTP commands (USER, PASS, STOR, RETR, LIST, CWD, PWD, QUIT). Supports anonymous access and serves files from a configurable root directory.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
oSocket | Object | Main listening TSocket |
cRootDir | Character | Default FTP directory (default "ftp") |
nPort | Numeric | Listening port (default 21) |
lDebug | Logical | Enable debug logging to cLogFile |
Methods
| Method | Description |
|---|---|
New( nPort ) | Create server; creates root dir if missing |
Activate() | Start listening for clients |
End() | Stop the server |
OnAccept() | Handle new client connections |
OnRead( oSocket ) | Process FTP commands from a client |
TFTP
Source: source/classes/tftp.prg
FTP client via WinINet. Supports directory listing, file deletion, rename, and directory management.
| Method | Description |
|---|---|
New( cFTPSite, oInternet, cUser, cPass ) | Connect to an FTP site |
Directory( cMask ) | Return array of remote file records |
DeleteFile( cFile ) | Delete a remote file |
RenameFile( cOld, cNew ) | Rename a remote file |
TFTPFile
Source: source/classes/tftpfile.prg
Manages individual remote file transfers. Supports ASCII and binary modes.
| Method | Description |
|---|---|
New( cFileName, oFTP ) | Create a file object |
OpenRead() / OpenWrite() | Open for reading or writing |
Read( nBytes ) / Write( cData ) | Read or write data |
Seek( nBytes, nFrom ) | Seek to a position |
End() | Close the file handle |
Example: Start FTP Server
#include "FiveWin.ch"
function Main()
local oServer
oServer := TFtpServer():New( 21 )
oServer:cRootDir = "c:\ftproot"
oServer:lDebug = .T.
oServer:Activate()
return nil
Notes
- TFtpServer supports anonymous login only; no password authentication is enforced.
- Commands handled: NOOP, USER, PASS, QUIT, CWD, CDUP, PWD, PORT, TYPE, RETR, STOR, LIST, SYST.
- TFTP client uses WinINet, requiring Internet Explorer components.
- TFTPFile supports binary (
lBinary := .T.) and ASCII transfer modes.