SalFtpClient
Namespace: PPJ.Runtime.Internet
Assembly: PPJ.Runtime.50 (5.0.0.0)
Provides synchronous FTP commands and passive data transfers with cancellable status notifications.
- C#
- VB.NET
public class SalFtpClient : IDisposable
Public Class SalFtpClient
Inherits IDisposable
Example:
using PPJ.Runtime.Internet;
using (var client = new SalFtpClient())
{
client.Server = "ftp.example.com";
client.User = "user";
client.Password = "password";
}
Constructors
SalFtpClient()
Initializes FTP connection settings without connecting.
SalFtpClient(server, user, password)
Initializes FTP connection settings without connecting.
| Name | Type | Description |
|---|---|---|
| server | String | The FTP server host name or address. |
| user | String | The login user name. |
| password | String | The login password. |
SalFtpClient(server, user, password, port)
Initializes FTP connection settings without connecting.
| Name | Type | Description |
|---|---|---|
| server | String | The FTP server host name or address. |
| user | String | The login user name. |
| password | String | The login password. |
| port | Int32 | The connection port, stored as supplied. |
Properties
BinaryMode
Boolean: Gets or sets whether transfers use binary mode.
Setting the property immediately sends TYPE I for binary or TYPE A for text, so an active connection is required.
Connected
Boolean: Gets the underlying control socket's connection state.
Returns false when no socket exists.
Password
String: Gets or sets the password sent when the server requests it.
Port
Int32: Gets or sets the FTP server port.
The default is 21. Assigning a nonpositive value through this property restores 21.
Server
String: Gets or sets the FTP server host name or address.
User
String: Gets or sets the user name sent during login.
Methods
AsyncDownload(fileName, localFileName, resume)
Starts Download through an asynchronous delegate and returns immediately.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The remote file name to download. |
| localFileName | String | The destination path, or null/empty to use the remote base name. |
| resume | Boolean | Whether to attempt continuation using the existing destination size and server REST support. |
The operation has no returned task or completion callback; this method does not wait for it or retrieve its exception.
AsyncUpload(fileName, remoteFileName, resume)
Starts Upload through an asynchronous delegate and returns immediately.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The local file path to upload. |
| remoteFileName | String | The required destination name on the FTP server. |
| resume | Boolean | Whether to attempt continuation using the existing destination size and server REST support. |
The operation has no returned task or completion callback; this method does not wait for it or retrieve its exception.
ChangeDir(dir)
Changes the current remote directory using CWD.
| Parameter | Type | Description |
|---|---|---|
| dir | String | The remote directory path. |
Null, empty, and dot paths are ignored.
Close()
Sends QUIT when connected, then releases the control socket.
Connect()
Connects to the configured FTP server and performs USER/PASS login.
Closes an existing connection first. Socket and server-response failures are reported as FtpException.
ConnectDataReader()
Opens a passive data connection wrapped in a text reader.
Returns: StreamReader. A reader for the passive data stream.
The caller must close the returned reader; closing it also closes the data socket.
ConnectDataSocket()
Requests passive mode and connects to the server-provided data endpoint.
Returns: Socket. The connected IPv4 data socket.
The caller owns and must close the returned socket.
DeleteFile(fileName)
Deletes a remote file using DELE.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The remote file name for download, deletion, or size queries; the local file path for uploads. |
Dispose()
Releases the control socket without sending QUIT.
Download(fileName)
Downloads a remote file to a local file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The remote file name to download. |
Without a local name, uses the remote base name in the current directory. Existing files are opened without truncation unless the resume logic determines they are larger than the remote file. Empty remote names are ignored.
Download(fileName, resume)
Downloads a remote file to a local file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The remote file name to download. |
| resume | Boolean | Whether to attempt continuation using the existing destination size and server REST support. |
Without a local name, uses the remote base name in the current directory. Existing files are opened without truncation unless the resume logic determines they are larger than the remote file. Empty remote names are ignored.
Download(fileName, localFileName)
Downloads a remote file to a local file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The remote file name to download. |
| localFileName | String | The destination path, or null/empty to use the remote base name. |
Without a local name, uses the remote base name in the current directory. Existing files are opened without truncation unless the resume logic determines they are larger than the remote file. Empty remote names are ignored.
Download(fileName, localFileName, resume)
Downloads a remote file to a local file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The remote file name to download. |
| localFileName | String | The destination path, or null/empty to use the remote base name. |
| resume | Boolean | Whether to attempt continuation using the existing destination size and server REST support. |
Without a local name, uses the remote base name in the current directory. Existing files are opened without truncation unless the resume logic determines they are larger than the remote file. Empty remote names are ignored.
Finalize()
GetCurDir()
Reads the current remote directory using PWD.
Returns: String. The path between quotes in the server reply.
GetFileInfo(mask)
Retrieves and parses a remote LIST response.
| Parameter | Type | Description |
|---|---|---|
| mask | String | The server-side name pattern or path. |
Returns: FtpFileInfo[]. One parsed file-information object per listing line, or an empty array for an empty or missing-file listing.
Recognizes Windows NT and Unix listing formats.
GetFileList(mask)
Retrieves matching remote names using NLST.
| Parameter | Type | Description |
|---|---|---|
| mask | String | The server-side name pattern or path. |
Returns: String[]. The received names, or an empty array for an empty or missing-file listing.
GetFileSize(fileName)
Requests the remote byte count with SIZE.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The remote file name for download, deletion, or size queries; the local file path for uploads. |
Returns: Int64. The size parsed from a 213 reply.
MakeDir(dir)
Creates a remote directory using MKD.
| Parameter | Type | Description |
|---|---|---|
| dir | String | The remote directory path. |
Null or empty paths are ignored.
ReadResponse()
Reads a control-channel response and combines multiline replies.
Returns: FtpResponse. The parsed response code and message.
Requires an active connection and a well-formed reply. Socket and input failures are wrapped in FtpException.
RemoveDir(dir)
Removes a remote directory using RMD.
| Parameter | Type | Description |
|---|---|---|
| dir | String | The remote directory path. |
Null or empty paths are ignored.
RenameFile(oldFileName, newFileName)
Renames a remote file using RNFR and RNTO.
| Parameter | Type | Description |
|---|---|---|
| oldFileName | String | The existing remote name. |
| newFileName | String | The replacement remote name. |
SendCommand(command, validCodes)
Sends an ASCII FTP command and validates the response.
| Parameter | Type | Description |
|---|---|---|
| command | String | The FTP command without its trailing CRLF. |
| validCodes | Int32[] | Accepted reply codes; an empty array accepts any parsed reply. |
Returns: FtpResponse. The server response.
Appends CRLF and raises request/response status notifications. Unexpected reply codes raise FtpException when valid codes are supplied.
Upload(fileName)
Uploads a local file to an explicitly named remote file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The local file path to upload. |
Overloads without a remote name do nothing because the delegated implementation requires a nonempty remote name. Missing local files raise FtpException.
Upload(fileName, resume)
Uploads a local file to an explicitly named remote file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The local file path to upload. |
| resume | Boolean | Whether to attempt continuation using the existing destination size and server REST support. |
Overloads without a remote name do nothing because the delegated implementation requires a nonempty remote name. Missing local files raise FtpException. The resume path currently sends REST only when the remote size exceeds the local size.
Upload(fileName, remoteFileName)
Uploads a local file to an explicitly named remote file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The local file path to upload. |
| remoteFileName | String | The required destination name on the FTP server. |
Overloads without a remote name do nothing because the delegated implementation requires a nonempty remote name. Missing local files raise FtpException.
Upload(fileName, remoteFileName, resume)
Uploads a local file to an explicitly named remote file.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | The local file path to upload. |
| remoteFileName | String | The required destination name on the FTP server. |
| resume | Boolean | Whether to attempt continuation using the existing destination size and server REST support. |
Overloads without a remote name do nothing because the delegated implementation requires a nonempty remote name. Missing local files raise FtpException. The resume path currently sends REST only when the remote size exceeds the local size.
Events
StatusUpdate
FtpEventHandler Occurs as the client advances through an operation.
Subscribers can cancel connecting, sending, receiving, and transfer-start notifications by setting Cancel; cancellation raises FtpException with code zero.