Skip to main content

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.

public class SalFtpClient : IDisposable

Example:

using PPJ.Runtime.Internet;

using (var client = new SalFtpClient())
{
client.Server = "ftp.example.com";
client.User = "user";
client.Password = "password";
}

Constructors

Instance member SalFtpClient()

Initializes FTP connection settings without connecting.

Instance member SalFtpClient(server, user, password)

Initializes FTP connection settings without connecting.

NameTypeDescription
serverStringThe FTP server host name or address.
userStringThe login user name.
passwordStringThe login password.

Instance member SalFtpClient(server, user, password, port)

Initializes FTP connection settings without connecting.

NameTypeDescription
serverStringThe FTP server host name or address.
userStringThe login user name.
passwordStringThe login password.
portInt32The connection port, stored as supplied.

Properties

Instance member 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.

Instance member Connected

Boolean: Gets the underlying control socket's connection state.

Returns false when no socket exists.

Instance member Password

String: Gets or sets the password sent when the server requests it.

Instance member Port

Int32: Gets or sets the FTP server port.

The default is 21. Assigning a nonpositive value through this property restores 21.

Instance member Server

String: Gets or sets the FTP server host name or address.

Instance member User

String: Gets or sets the user name sent during login.

Methods

Instance member AsyncDownload(fileName, localFileName, resume)

Starts Download through an asynchronous delegate and returns immediately.

ParameterTypeDescription
fileNameStringThe remote file name to download.
localFileNameStringThe destination path, or null/empty to use the remote base name.
resumeBooleanWhether 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.

Instance member AsyncUpload(fileName, remoteFileName, resume)

Starts Upload through an asynchronous delegate and returns immediately.

ParameterTypeDescription
fileNameStringThe local file path to upload.
remoteFileNameStringThe required destination name on the FTP server.
resumeBooleanWhether 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.

Instance member ChangeDir(dir)

Changes the current remote directory using CWD.

ParameterTypeDescription
dirStringThe remote directory path.

Null, empty, and dot paths are ignored.

Instance member Close()

Sends QUIT when connected, then releases the control socket.

Instance member 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.

Instance member 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.

Instance member 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.

Instance member DeleteFile(fileName)

Deletes a remote file using DELE.

ParameterTypeDescription
fileNameStringThe remote file name for download, deletion, or size queries; the local file path for uploads.

Instance member Dispose()

Releases the control socket without sending QUIT.

Instance member Download(fileName)

Downloads a remote file to a local file.

ParameterTypeDescription
fileNameStringThe 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.

Instance member Download(fileName, resume)

Downloads a remote file to a local file.

ParameterTypeDescription
fileNameStringThe remote file name to download.
resumeBooleanWhether 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.

Instance member Download(fileName, localFileName)

Downloads a remote file to a local file.

ParameterTypeDescription
fileNameStringThe remote file name to download.
localFileNameStringThe 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.

Instance member Download(fileName, localFileName, resume)

Downloads a remote file to a local file.

ParameterTypeDescription
fileNameStringThe remote file name to download.
localFileNameStringThe destination path, or null/empty to use the remote base name.
resumeBooleanWhether 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.

Protected member Finalize()

Instance member GetCurDir()

Reads the current remote directory using PWD.

Returns: String. The path between quotes in the server reply.

Instance member GetFileInfo(mask)

Retrieves and parses a remote LIST response.

ParameterTypeDescription
maskStringThe 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.

Instance member GetFileList(mask)

Retrieves matching remote names using NLST.

ParameterTypeDescription
maskStringThe server-side name pattern or path.

Returns: String[]. The received names, or an empty array for an empty or missing-file listing.

Instance member GetFileSize(fileName)

Requests the remote byte count with SIZE.

ParameterTypeDescription
fileNameStringThe remote file name for download, deletion, or size queries; the local file path for uploads.

Returns: Int64. The size parsed from a 213 reply.

Instance member MakeDir(dir)

Creates a remote directory using MKD.

ParameterTypeDescription
dirStringThe remote directory path.

Null or empty paths are ignored.

Instance member 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.

Instance member RemoveDir(dir)

Removes a remote directory using RMD.

ParameterTypeDescription
dirStringThe remote directory path.

Null or empty paths are ignored.

Instance member RenameFile(oldFileName, newFileName)

Renames a remote file using RNFR and RNTO.

ParameterTypeDescription
oldFileNameStringThe existing remote name.
newFileNameStringThe replacement remote name.

Instance member SendCommand(command, validCodes)

Sends an ASCII FTP command and validates the response.

ParameterTypeDescription
commandStringThe FTP command without its trailing CRLF.
validCodesInt32[]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.

Instance member Upload(fileName)

Uploads a local file to an explicitly named remote file.

ParameterTypeDescription
fileNameStringThe 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.

Instance member Upload(fileName, resume)

Uploads a local file to an explicitly named remote file.

ParameterTypeDescription
fileNameStringThe local file path to upload.
resumeBooleanWhether 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.

Instance member Upload(fileName, remoteFileName)

Uploads a local file to an explicitly named remote file.

ParameterTypeDescription
fileNameStringThe local file path to upload.
remoteFileNameStringThe 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.

Instance member Upload(fileName, remoteFileName, resume)

Uploads a local file to an explicitly named remote file.

ParameterTypeDescription
fileNameStringThe local file path to upload.
remoteFileNameStringThe required destination name on the FTP server.
resumeBooleanWhether 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

Instance member 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.