Table of Contents

Class FtpClient

Namespace
FluentFTP
Assembly
FluentFTP.dll

An FTP client that manages a connection to a single FTP server. Interacts with any FTP/FTPS server and provides a high-level and low-level API to work with files and folders. Uses synchronous operations only. For the async version use AsyncFtpClient.

Debugging problems with FTP is much easier when you enable logging. Visit our Github Wiki for more info.

public class FtpClient : BaseFtpClient, IInternalFtpClient, IFtpClient, IDisposable, IBaseFtpClient
Inheritance
FtpClient
Implements
Derived
Inherited Members
Extension Methods

Constructors

FtpClient()

Creates a new instance of a synchronous FTP Client. You will have to setup the FTP host and credentials before connecting.

public FtpClient()

FtpClient(string, int, FtpConfig, IFtpLogger)

Creates a new instance of a synchronous FTP Client, with the given host and credentials.

public FtpClient(string host, int port = 0, FtpConfig config = null, IFtpLogger logger = null)

Parameters

host string
port int
config FtpConfig
logger IFtpLogger

FtpClient(string, NetworkCredential, int, FtpConfig, IFtpLogger)

Creates a new instance of a synchronous FTP Client, with the given host and credentials.

public FtpClient(string host, NetworkCredential credentials, int port = 0, FtpConfig config = null, IFtpLogger logger = null)

Parameters

host string
credentials NetworkCredential
port int
config FtpConfig
logger IFtpLogger

FtpClient(string, string, string, int, FtpConfig, IFtpLogger)

Creates a new instance of a synchronous FTP Client, with the given host and credentials.

public FtpClient(string host, string user, string pass, int port = 0, FtpConfig config = null, IFtpLogger logger = null)

Parameters

host string
user string
pass string
port int
config FtpConfig
logger IFtpLogger

Methods

Authenticate()

Performs a login on the server. This method is overridable so that the login procedure can be changed to support, for example, a FTP proxy.

protected virtual void Authenticate()

Authenticate(string, string, string)

Performs a login on the server. This method is overridable so that the login procedure can be changed to support, for example, a FTP proxy.

protected virtual void Authenticate(string userName, string password, string account)

Parameters

userName string
password string
account string

Remarks

To handle authentication failures without retries, catch FtpAuthenticationException.

Exceptions

FtpAuthenticationException

On authentication failures

AutoConnect()

Automatic FTP and FTPS connection negotiation. This method tries every possible combination of the FTP connection properties, and connects to the first successful profile. Returns the FtpProfile if the connection succeeded, or null if it failed. It will throw exceptions for permanent failures like invalid host or invalid credentials.

public FtpProfile AutoConnect()

Returns

FtpProfile

AutoDetect(FtpAutoDetectConfig)

Automatic FTP and FTPS connection negotiation. This method tries every possible combination of the FTP connection properties, and returns the list of successful connection profiles. You can configure it to stop after finding the first successful profile, or to collect all successful profiles. You can then generate code for the profile using the FtpProfile.ToCode method. If no successful profiles are found, a blank list is returned.

public List<FtpProfile> AutoDetect(FtpAutoDetectConfig config = null)

Parameters

config FtpAutoDetectConfig

The coresponding config object for this API

Returns

List<FtpProfile>

AutoDetect(bool, bool)

LEGACY CALL FORMAT, to be deleted sometime in the future

Automatic FTP and FTPS connection negotiation. This method tries every possible combination of the FTP connection properties, and returns the list of successful connection profiles. You can configure it to stop after finding the first successful profile, or to collect all successful profiles. You can then generate code for the profile using the FtpProfile.ToCode method. If no successful profiles are found, a blank list is returned.

public List<FtpProfile> AutoDetect(bool firstOnly = true, bool cloneConnection = true)

Parameters

firstOnly bool

Find all successful profiles (false) or stop after finding the first successful profile (true)

cloneConnection bool

Use a new cloned FtpClient for testing connection profiles (true) or use the source FtpClient (false)

Returns

List<FtpProfile>

Chmod(string, FtpPermission, FtpPermission, FtpPermission)

Modify the permissions of the given file/folder. Only works on *NIX systems, and not on Windows/IIS servers. Only works if the FTP server supports the SITE CHMOD command (requires the CHMOD extension to be installed and enabled). Throws FtpCommandException if there is an issue.

public void Chmod(string path, FtpPermission owner, FtpPermission group, FtpPermission other)

Parameters

path string

The full or relative path to the item

owner FtpPermission

The owner permissions

group FtpPermission

The group permissions

other FtpPermission

The other permissions

Chmod(string, int)

Modify the permissions of the given file/folder. Only works on *NIX systems, and not on Windows/IIS servers. Only works if the FTP server supports the SITE CHMOD command (requires the CHMOD extension to be installed and enabled). Throws FtpCommandException if there is an issue.

public void Chmod(string path, int permissions)

Parameters

path string

The full or relative path to the item

permissions int

The permissions in CHMOD format

CompareFile(string, string, FtpCompareOption)

Compare the specified local file with the remote file on the FTP server using various kinds of quick equality checks. In Auto mode, the file size and checksum are compared. Comparing the checksum of a file is a quick way to check if the contents of the files are exactly equal without downloading a copy of the file. You can use the option flags to compare any combination of: file size, checksum, date modified.

public FtpCompareResult CompareFile(string localPath, string remotePath, FtpCompareOption options = FtpCompareOption.Auto)

Parameters

localPath string

The full or relative path to the file on the local file system

remotePath string

The full or relative path to the file on the server

options FtpCompareOption

Types of equality checks to perform. Use Auto to compare file size and checksum.

Returns

FtpCompareResult

Connect()

Connect

public virtual void Connect()

Connect(FtpProfile)

Connect to the given server profile.

public void Connect(FtpProfile profile)

Parameters

profile FtpProfile

Connect(FtpSocketStream)

Connect to the FTP server. Overridden in proxy classes.

protected virtual void Connect(FtpSocketStream stream)

Parameters

stream FtpSocketStream

Connect(FtpSocketStream, string, int, FtpIpVersion)

Connect to the FTP server. Overridden in proxy classes.

protected virtual void Connect(FtpSocketStream stream, string host, int port, FtpIpVersion ipVersions)

Parameters

stream FtpSocketStream
host string
port int
ipVersions FtpIpVersion

Connect(bool)

Connect to the server

public virtual void Connect(bool reConnect)

Parameters

reConnect bool

true indicates that we want a reconnect to take place.

Exceptions

ObjectDisposedException

Thrown if this object has been disposed.

Create()

Creates a new instance of this class. Useful in FTP proxy classes.

protected override BaseFtpClient Create()

Returns

BaseFtpClient

CreateDirectory(string)

Creates a directory on the server. If the preceding directories do not exist, then they are created.

public bool CreateDirectory(string path)

Parameters

path string

The full or relative path to the new remote directory

Returns

bool

CreateDirectory(string, bool)

Creates a directory on the server

public bool CreateDirectory(string path, bool force)

Parameters

path string

The full or relative path to the new remote directory

force bool

Try to force all non-existent pieces of the path to be created

Returns

bool

True if directory was created, false if it was skipped

CreateSubDirectories(FtpClient, List<FtpResult>)

Create all the sub directories within the main directory

protected void CreateSubDirectories(FtpClient client, List<FtpResult> dirsToUpload)

Parameters

client FtpClient
dirsToUpload List<FtpResult>

DeleteDirInternal(string, bool, FtpListOption, bool, bool)

Deletes the specified directory and all its contents.

protected void DeleteDirInternal(string path, bool deleteContents, FtpListOption options, bool deleteFinalDir, bool firstCall)

Parameters

path string

The full or relative path of the directory to delete

deleteContents bool

If the directory is not empty, remove its contents

options FtpListOption

Useful to delete hidden files or dot-files.

deleteFinalDir bool

Delete completely or leave the top level dir

firstCall bool

Internally used to determine top level

DeleteDirectory(string)

Deletes the specified directory and all its contents.

public void DeleteDirectory(string path)

Parameters

path string

The full or relative path of the directory to delete

DeleteDirectory(string, FtpListOption)

Deletes the specified directory and all its contents.

public void DeleteDirectory(string path, FtpListOption options)

Parameters

path string

The full or relative path of the directory to delete

options FtpListOption

Useful to delete hidden files or dot-files.

DeleteExtraServerFiles(FtpFolderSyncMode, string, Dictionary<string, bool>, FtpListItem[], List<FtpRule>)

Delete the extra remote files if in mirror mode and the directory was pre-existing

protected void DeleteExtraServerFiles(FtpFolderSyncMode mode, string remoteFolder, Dictionary<string, bool> shouldExist, FtpListItem[] remoteListing, List<FtpRule> rules)

Parameters

mode FtpFolderSyncMode
remoteFolder string
shouldExist Dictionary<string, bool>
remoteListing FtpListItem[]
rules List<FtpRule>

DeleteFile(string)

Deletes a file on the server

public void DeleteFile(string path)

Parameters

path string

The full or relative path to the file

DirectoryExists(string)

Tests if the specified directory exists on the server. This method works by trying to change the working directory to the path specified. If it succeeds, the directory is changed back to the old working directory and true is returned. False is returned otherwise and since the CWD failed it is assumed the working directory is still the same.

public bool DirectoryExists(string path)

Parameters

path string

The path of the directory

Returns

bool

True if it exists, false otherwise.

DisableUTF8()

Disables UTF8 support and changes the Encoding property back to ASCII. If the server returns an error when trying to turn UTF8 off a FtpCommandException will be thrown.

public void DisableUTF8()

Disconnect()

Disconnects from the server

public void Disconnect()

DiscoverSslSessionLength(string, int)

Automatically discover the SSL command limit of your currently connected FTP server. It returns the value that can be used to set SslSessionLength.

public int DiscoverSslSessionLength(string command = "PWD", int maxTries = 2000)

Parameters

command string

The command to issue

maxTries int

Maximum number of commands to issue

Returns

int

The detected command limit, 0 if infinite

DownloadBytes(out byte[], string, long, Action<FtpProgress>, long)

Downloads the specified file and return the raw byte array. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks.

public bool DownloadBytes(out byte[] outBytes, string remotePath, long restartPosition = 0, Action<FtpProgress> progress = null, long stopPosition = 0)

Parameters

outBytes byte[]

The variable that will receive the bytes.

remotePath string

The full or relative path to the file on the server

restartPosition long

The size of the existing file in bytes, or 0 if unknown. The download restarts from this byte index.

progress Action<FtpProgress>

Provide a callback to track download progress.

stopPosition long

The last byte index that should be downloaded, or 0 if the entire file should be downloaded.

Returns

bool

If true then the file was downloaded, false otherwise.

DownloadDirectory(string, string, FtpFolderSyncMode, FtpLocalExists, FtpVerify, List<FtpRule>, Action<FtpProgress>)

Downloads the specified directory onto the local file system. In Mirror mode, we will download missing files, and delete any extra files from disk that are not present on the server. This is very useful when creating an exact local backup of an FTP directory. In Update mode, we will only download missing files and preserve any extra files on disk. This is useful when you want to simply download missing files from an FTP directory. Only downloads the files and folders matching all the rules provided, if any. All exceptions during downloading are caught, and the exception is stored in the related FtpResult object.

public List<FtpResult> DownloadDirectory(string localFolder, string remoteFolder, FtpFolderSyncMode mode = FtpFolderSyncMode.Update, FtpLocalExists existsMode = FtpLocalExists.Skip, FtpVerify verifyOptions = FtpVerify.None, List<FtpRule> rules = null, Action<FtpProgress> progress = null)

Parameters

localFolder string

The full path of the local folder on disk to download into. It is created if it does not exist.

remoteFolder string

The full path of the remote FTP folder that you want to download. If it does not exist, an empty result list is returned.

mode FtpFolderSyncMode

Mirror or Update mode, as explained above

existsMode FtpLocalExists

If the file exists on disk, should we skip it, resume the download or restart the download?

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

rules List<FtpRule>

Only files and folders that pass all these rules are downloaded, and the files that don't pass are skipped. In the Mirror mode, the files that fail the rules are also deleted from the local folder.

progress Action<FtpProgress>

Provide a callback to track download progress.

Returns

List<FtpResult>

Returns a listing of all the remote files, indicating if they were downloaded, skipped or overwritten. Returns a blank list if nothing was transferred. Never returns null.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

DownloadFile(string, string, FtpLocalExists, FtpVerify, Action<FtpProgress>)

Downloads the specified file onto the local file system. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks.

public FtpStatus DownloadFile(string localPath, string remotePath, FtpLocalExists existsMode = FtpLocalExists.Overwrite, FtpVerify verifyOptions = FtpVerify.None, Action<FtpProgress> progress = null)

Parameters

localPath string

The full or relative path to the file on the local file system

remotePath string

The full or relative path to the file on the server

existsMode FtpLocalExists

If the file exists on disk, should we skip it, resume the download or restart the download?

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

progress Action<FtpProgress>

Provide a callback to track download progress.

Returns

FtpStatus

FtpStatus flag indicating if the file was downloaded, skipped or failed to transfer.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

DownloadFileInternal(string, string, Stream, long, Action<FtpProgress>, FtpProgress, long, bool, long)

Download a file from the server and write the data into the given stream. Reads data in chunks. Retries if server disconnects midway.

protected bool DownloadFileInternal(string localPath, string remotePath, Stream outStream, long restartPosition, Action<FtpProgress> progress, FtpProgress metaProgress, long knownFileSize, bool isAppend, long stopPosition)

Parameters

localPath string
remotePath string
outStream Stream
restartPosition long
progress Action<FtpProgress>
metaProgress FtpProgress
knownFileSize long
isAppend bool
stopPosition long

Returns

bool

DownloadFileToFile(string, string, FtpLocalExists, FtpVerify, Action<FtpProgress>, FtpProgress)

Download from a remote file to a local file

protected FtpStatus DownloadFileToFile(string localPath, string remotePath, FtpLocalExists existsMode, FtpVerify verifyOptions, Action<FtpProgress> progress, FtpProgress metaProgress)

Parameters

localPath string
remotePath string
existsMode FtpLocalExists
verifyOptions FtpVerify
progress Action<FtpProgress>
metaProgress FtpProgress

Returns

FtpStatus

Exceptions

ArgumentException
FtpException

DownloadFiles(string, IEnumerable<string>, FtpLocalExists, FtpVerify, FtpError, Action<FtpProgress>, List<FtpRule>)

Downloads the specified files into a local single directory. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks. Same speed as .

public List<FtpResult> DownloadFiles(string localDir, IEnumerable<string> remotePaths, FtpLocalExists existsMode = FtpLocalExists.Overwrite, FtpVerify verifyOptions = FtpVerify.None, FtpError errorHandling = FtpError.None, Action<FtpProgress> progress = null, List<FtpRule> rules = null)

Parameters

localDir string

The full or relative path to the directory that files will be downloaded into.

remotePaths IEnumerable<string>

The full or relative paths to the files on the server

existsMode FtpLocalExists

If the file exists on disk, should we skip it, resume the download or restart the download?

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

errorHandling FtpError

Used to determine how errors are handled

progress Action<FtpProgress>

Provide an implementation of IProgress to track upload progress.

rules List<FtpRule>

Only files that pass all these rules are downloaded, and the files that don't pass are skipped.

Returns

List<FtpResult>

Returns a listing of all the remote files, indicating if they were downloaded, skipped or overwritten. Returns a blank list if nothing was transferred. Never returns null.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

DownloadServerFiles(List<FtpResult>, FtpLocalExists, FtpVerify, Action<FtpProgress>)

Download all the listed files and folders from the main directory

protected void DownloadServerFiles(List<FtpResult> toDownload, FtpLocalExists existsMode, FtpVerify verifyOptions, Action<FtpProgress> progress)

Parameters

toDownload List<FtpResult>
existsMode FtpLocalExists
verifyOptions FtpVerify
progress Action<FtpProgress>

DownloadStream(Stream, string, long, Action<FtpProgress>, long)

Downloads the specified file into the specified stream. High-level API that takes care of various edge cases internally. Supports very large files since it downloads data in chunks.

public bool DownloadStream(Stream outStream, string remotePath, long restartPosition = 0, Action<FtpProgress> progress = null, long stopPosition = 0)

Parameters

outStream Stream

The stream that the file will be written to. Provide a new MemoryStream if you only want to read the file into memory.

remotePath string

The full or relative path to the file on the server

restartPosition long

The size of the existing file in bytes, or 0 if unknown. The download restarts from this byte index.

progress Action<FtpProgress>

Provide a callback to track download progress.

stopPosition long

The last byte index that should be downloaded, or 0 if the entire file should be downloaded.

Returns

bool

If true then the file was downloaded, false otherwise.

DownloadUriBytes(out byte[], string, Action<FtpProgress>)

Downloads the specified uri and return the raw byte array.

public bool DownloadUriBytes(out byte[] outBytes, string uri, Action<FtpProgress> progress = null)

Parameters

outBytes byte[]

The variable that will receive the bytes.

uri string

The uri of the item to download

progress Action<FtpProgress>

Provide a callback to track download progress.

Returns

bool

Downloaded byte array

EmptyDirectory(string)

Deletes the contents of the specified directory, without deleting the directory itself.

public void EmptyDirectory(string path)

Parameters

path string

The full or relative path of the directorys contents to delete

EmptyDirectory(string, FtpListOption)

Deletes the contents of the specified directory, without deleting the directory itself.

public void EmptyDirectory(string path, FtpListOption options = FtpListOption.Recursive)

Parameters

path string

The full or relative path of the directorys contents to delete

options FtpListOption

Useful to delete hidden files or dot-files.

Execute(string)

Executes a command

public FtpReply Execute(string command)

Parameters

command string

The command to execute

Returns

FtpReply

The servers reply to the command

ExecuteDownloadText(string)

Execute a custom FTP command and read the data channel to return its multiline output.

public List<string> ExecuteDownloadText(string command)

Parameters

command string

The command to issue which produces output

Returns

List<string>

A list of string objects corresponding to the multi-line response by the server

ExecuteDownloadTextInternal(string, bool)

Execute a custom FTP command and return its multiline output.

protected List<string> ExecuteDownloadTextInternal(string command, bool retry)

Parameters

command string

The command to issue which produces output

retry bool

Retry the command execution on temporary failure?

Returns

List<string>

FileExists(string)

Checks if a file exists on the server.

public bool FileExists(string path)

Parameters

path string

The full or relative path to the file

Returns

bool

True if the file exists

GetAbsoluteDir(string)

Ensure a relative dir is absolute by prepending the working dir

protected string GetAbsoluteDir(string path)

Parameters

path string

Returns

string

GetAbsoluteFilePath(string, string)

Concat a path and a filename

protected string GetAbsoluteFilePath(string path, string fileName)

Parameters

path string
fileName string

Returns

string

GetAbsolutePath(string)

Ensure a relative path is absolute by prepending the working dir

protected string GetAbsolutePath(string path)

Parameters

path string

Returns

string

GetChecksum(string, FtpHashAlgorithm)

Retrieves a checksum of the given file using the specified checksum algorithm, or using the first available algorithm that the server supports.

public FtpHash GetChecksum(string remotePath, FtpHashAlgorithm algorithm = FtpHashAlgorithm.NONE)

Parameters

remotePath string
algorithm FtpHashAlgorithm

Specify an algorithm that you prefer, or NONE to use the first available algorithm. If the preferred algorithm is not supported, a blank hash is returned.

Returns

FtpHash

FtpHash object containing the value and algorithm. Use the IsValid property to determine if this command was successful. FtpCommandExceptions can be thrown from the underlying calls.

Remarks

The algorithm used goes in this order:

  1. HASH command using the first supported algorithm.
  2. MD5 / XMD5 / MMD5 commands
  3. XSHA1 command
  4. XSHA256 command
  5. XSHA512 command
  6. XCRC command

Exceptions

FtpCommandException

The command fails

GetChmod(string)

Retrieve the permissions of the given file/folder as an integer in the CHMOD format. Throws FtpCommandException if there is an issue. Returns 0 if the server did not specify a permission value. Use GetFilePermissions if you required the permissions in the FtpPermission format.

public int GetChmod(string path)

Parameters

path string

The full or relative path to the item

Returns

int

GetFilePermissions(string)

Retrieve the permissions of the given file/folder as an FtpListItem object with all "Permission" properties set. Throws FtpCommandException if there is an issue. Returns null if the server did not specify a permission value. Use GetChmod if you required the integer value instead.

public FtpListItem GetFilePermissions(string path)

Parameters

path string

The full or relative path to the item

Returns

FtpListItem

GetFileSize(string, long)

Gets the size of a remote file, in bytes.

public virtual long GetFileSize(string path, long defaultValue = -1)

Parameters

path string

The full or relative path of the file

defaultValue long

Value to return if there was an error obtaining the file size, or if the file does not exist

Returns

long

The size of the file, or defaultValue if there was a problem.

GetFileSizeInternal(string, FtpSizeReply, long)

Gets the file size of an object, without locking

protected void GetFileSizeInternal(string path, FtpSizeReply sizeReply, long defaultValue)

Parameters

path string
sizeReply FtpSizeReply
defaultValue long

GetFilesToTransfer(string, string, List<FtpRule>, List<FtpResult>, Dictionary<string, bool>, string[])

Make a list of files to transfer

protected List<FtpResult> GetFilesToTransfer(string sourceFolder, string remoteFolder, List<FtpRule> rules, List<FtpResult> results, Dictionary<string, bool> shouldExist, string[] fileListing)

Parameters

sourceFolder string
remoteFolder string
rules List<FtpRule>
results List<FtpResult>
shouldExist Dictionary<string, bool>
fileListing string[]

Returns

List<FtpResult>

GetFilesToUpload2(IEnumerable<string>, string, List<FtpRule>, List<FtpResult>, Dictionary<string, bool>)

Get a list of all the files that need to be uploaded

protected List<FtpResult> GetFilesToUpload2(IEnumerable<string> localFiles, string remoteDir, List<FtpRule> rules, List<FtpResult> results, Dictionary<string, bool> shouldExist)

Parameters

localFiles IEnumerable<string>
remoteDir string
rules List<FtpRule>
results List<FtpResult>
shouldExist Dictionary<string, bool>

Returns

List<FtpResult>

GetListing()

Gets a file listing from the server from the current working directory. Each FtpListItem object returned contains information about the file that was able to be retrieved.

public FtpListItem[] GetListing()

Returns

FtpListItem[]

An array of FtpListItem objects

Remarks

If a DateTime property is equal to MinValue then it means the date in question was not able to be retrieved. If the Size property is equal to 0, then it means the size of the object could also not be retrieved.

GetListing(string)

Gets a file listing from the server. Each FtpListItem object returned contains information about the file that was able to be retrieved.

public FtpListItem[] GetListing(string path)

Parameters

path string

The path of the directory to list

Returns

FtpListItem[]

An array of FtpListItem objects

Remarks

If a DateTime property is equal to MinValue then it means the date in question was not able to be retrieved. If the Size property is equal to 0, then it means the size of the object could also not be retrieved.

GetListing(string, FtpListOption)

Gets a file listing from the server. Each FtpListItem object returned contains information about the file that was able to be retrieved.

public FtpListItem[] GetListing(string path, FtpListOption options)

Parameters

path string

The path of the directory to list

options FtpListOption

Options that dictate how a list is performed and what information is gathered.

Returns

FtpListItem[]

An array of FtpListItem objects

Remarks

If a DateTime property is equal to MinValue then it means the date in question was not able to be retrieved. If the Size property is equal to 0, then it means the size of the object could also not be retrieved.

GetListingInternal(string, FtpListOption, bool)

Get the records of a file listing and retry if temporary failure.

protected List<string> GetListingInternal(string listcmd, FtpListOption options, bool retry)

Parameters

listcmd string
options FtpListOption
retry bool

Returns

List<string>

GetListingRecursive(string, FtpListOption)

Recursive method of GetListing, to recurse through directories on servers that do not natively support recursion. Automatically called by GetListing where required. Uses flat recursion instead of head recursion.

protected FtpListItem[] GetListingRecursive(string path, FtpListOption options)

Parameters

path string

The path of the directory to list

options FtpListOption

Options that dictate how a list is performed and what information is gathered.

Returns

FtpListItem[]

An array of FtpListItem objects

GetModifiedTime(string)

Gets the modified time of a remote file.

public virtual DateTime GetModifiedTime(string path)

Parameters

path string

The full path to the file

Returns

DateTime

The modified time, or MinValue if there was a problem

GetNameListing()

Returns a file/directory listing using the NLST command.

public string[] GetNameListing()

Returns

string[]

A string array of file and directory names if any were returned.

GetNameListing(string)

Returns a file/directory listing using the NLST command.

public string[] GetNameListing(string path)

Parameters

path string

The path of the directory to list

Returns

string[]

A string array of file and directory names if any were returned.

GetObjectInfo(string, bool)

Returns information about a file system object. Returns null if the server response can't be parsed or the server returns a failure completion code. The error for a failure is logged with FtpTrace. No exception is thrown on error because that would negate the usefulness of this method for checking for the existence of an object.

public FtpListItem GetObjectInfo(string path, bool dateModified = false)

Parameters

path string

The path of the file or folder

dateModified bool

Get the accurate modified date using another MDTM command

Returns

FtpListItem

A FtpListItem object

GetReply()

Retrieves a reply from the server. Support "normal" mode waiting for a command reply, subject to timeout exception and "exhaustNoop" mode, which waits for 10 seconds to collect out of band NOOP responses

public FtpReply GetReply()

Returns

FtpReply

FtpReply representing the response from the server

GetWorkingDirectory()

Gets the current working directory

public string GetWorkingDirectory()

Returns

string

The current working directory, ./ if the response couldn't be parsed.

GetZOSListRealm()

If an FTP Server has "different realms", in which realm is the current working directory.

public FtpZOSListRealm GetZOSListRealm()

Returns

FtpZOSListRealm

The realm

Handshake()

Called during Connect(). Typically extended by FTP proxies.

protected virtual void Handshake()

HashCommandInternal(string)

Gets the hash of an object on the server using the currently selected hash algorithm.

protected FtpHash HashCommandInternal(string remotePath)

Parameters

remotePath string

Returns

FtpHash

IsRoot()

Is the current working directory the root?

public bool IsRoot()

Returns

bool

true if root.

IsStillConnected(int)

Performs a series of tests to check if we are still connected to the FTP server. More thourough than IsConnected.

public bool IsStillConnected(int timeout = 10000)

Parameters

timeout int

Returns

bool

bool connection status

MoveDirectory(string, string, FtpRemoteExists)

Moves a directory on the remote file system from one directory to another. Always checks if the source directory exists. Checks if the dest directory exists based on the existsMode parameter. Only throws exceptions for critical errors.

public bool MoveDirectory(string path, string dest, FtpRemoteExists existsMode = FtpRemoteExists.Overwrite)

Parameters

path string

The full or relative path to the object

dest string

The new full or relative path including the new name of the object

existsMode FtpRemoteExists

Should we check if the dest directory exists? And if it does should we overwrite/skip the operation?

Returns

bool

Whether the directory was moved

MoveFile(string, string, FtpRemoteExists)

Moves a file on the remote file system from one directory to another. Always checks if the source file exists. Checks if the dest file exists based on the existsMode parameter. Only throws exceptions for critical errors.

public bool MoveFile(string path, string dest, FtpRemoteExists existsMode = FtpRemoteExists.Overwrite)

Parameters

path string

The full or relative path to the object

dest string

The new full or relative path including the new name of the object

existsMode FtpRemoteExists

Should we check if the dest file exists? And if it does should we overwrite/skip the operation?

Returns

bool

Whether the file was moved

Noop(bool)

Sends the NOOP command according to NoopInterval (effectively a no-op if 0). Please call GetReply() as needed to read the "OK" command sent by the server and prevent stale data on the socket. Note that response is not guaranteed by all FTP servers when sent during file transfers.

Send the command regardless of NoopInterval
public bool Noop(bool ignoreNoopInterval = false)

Parameters

ignoreNoopInterval bool

Returns

bool

true if NOOP command was sent

OpenActiveDataStream(FtpDataConnectionType, string, long)

Opens the specified type of active data stream

protected FtpDataStream OpenActiveDataStream(FtpDataConnectionType type, string command, long restart)

Parameters

type FtpDataConnectionType

Type of passive data stream to open

command string

The command to execute that requires a data stream

restart long

Restart location in bytes for file transfer

Returns

FtpDataStream

A data stream ready to be used

OpenAppend(string, FtpDataType, bool)

Opens the specified file for appending. Please call GetReply() after you have successfully transferred the file to read the "OK" command sent by the server and prevent stale data on the socket.

public virtual Stream OpenAppend(string path, FtpDataType type = FtpDataType.Binary, bool checkIfFileExists = true)

Parameters

path string

The full or relative path to the file to be opened

type FtpDataType

ASCII/Binary

checkIfFileExists bool

Only set this to false if you are SURE that the file does not exist. If true, it reads the file size and saves it into the stream length.

Returns

Stream

A stream for appending to the file on the server

OpenAppend(string, FtpDataType, long)

Opens the specified file for appending. Please call GetReply() after you have successfully transferred the file to read the "OK" command sent by the server and prevent stale data on the socket.

public virtual Stream OpenAppend(string path, FtpDataType type, long fileLen)

Parameters

path string

The full or relative path to the file to be opened

type FtpDataType

ASCII/Binary

fileLen long

Pass in a file length if known


-1 => File length is irrelevant, do not attempt to determine it

0 => File length is unknown, try to determine it

>0 => File length is KNOWN. No need to determine it

Returns

Stream

A stream for appending to the file on the server

OpenAppendInternal(string, FtpDataType, long, bool)

Internal routine

public virtual Stream OpenAppendInternal(string path, FtpDataType type, long fileLen, bool ignoreStaleData)

Parameters

path string
type FtpDataType
fileLen long
ignoreStaleData bool

Normally false. Obsolete API uses true

Returns

Stream

A stream for appending the file on the server

OpenDataStream(string, long)

Opens a data stream.

protected FtpDataStream OpenDataStream(string command, long restart)

Parameters

command string

The command to execute that requires a data stream

restart long

Restart location in bytes for file transfer

Returns

FtpDataStream

The data stream.

OpenPassiveDataStream(FtpDataConnectionType, string, long)

Opens the specified type of passive data stream

protected FtpDataStream OpenPassiveDataStream(FtpDataConnectionType type, string command, long restart)

Parameters

type FtpDataConnectionType

Type of passive data stream to open

command string

The command to execute that requires a data stream

restart long

Restart location in bytes for file transfer

Returns

FtpDataStream

A data stream ready to be used

OpenPassiveFXPConnection(FtpClient, bool)

Opens a FXP PASV connection between the source FTP Server and the destination FTP Server

protected FtpFxpSession OpenPassiveFXPConnection(FtpClient remoteClient, bool progress)

Parameters

remoteClient FtpClient

FtpClient instance of the destination FTP Server

progress bool

Provide an implementation of IProgress to track download progress.

Returns

FtpFxpSession

A data stream ready to be used

OpenRead(string, FtpDataType, long, bool)

Opens the specified file for reading

public virtual Stream OpenRead(string path, FtpDataType type = FtpDataType.Binary, long restart = 0, bool checkIfFileExists = true)

Parameters

path string

The full or relative path of the file

type FtpDataType

ASCII/Binary

restart long

Resume location

checkIfFileExists bool

Only set this to false if you are SURE that the file does not exist. If true, it reads the file size and saves it into the stream length.

Returns

Stream

A stream for reading the file on the server

OpenRead(string, FtpDataType, long, long)

Opens the specified file for reading

public virtual Stream OpenRead(string path, FtpDataType type, long restart, long fileLen)

Parameters

path string

The full or relative path of the file

type FtpDataType

ASCII/Binary

restart long

Resume location

fileLen long

Pass in a file length if known


-1 => File length is irrelevant, do not attempt to determine it

0 => File length is unknown, try to determine it

>0 => File length is KNOWN. No need to determine it

Returns

Stream

A stream for reading the file on the server

OpenReadInternal(string, FtpDataType, long, long, bool)

Internal routine

public virtual Stream OpenReadInternal(string path, FtpDataType type, long fileLen, long restart, bool ignoreStaleData)

Parameters

path string
type FtpDataType
fileLen long
restart long
ignoreStaleData bool

Normally false. Obsolete API uses true

Returns

Stream

A stream for reading the file on the server

OpenWrite(string, FtpDataType, bool)

Opens the specified file for writing. Please call GetReply() after you have successfully transferred the file to read the "OK" command sent by the server and prevent stale data on the socket.

public virtual Stream OpenWrite(string path, FtpDataType type = FtpDataType.Binary, bool checkIfFileExists = true)

Parameters

path string

Full or relative path of the file

type FtpDataType

ASCII/Binary

checkIfFileExists bool

Only set this to false if you are SURE that the file does not exist. If true, it reads the file size and saves it into the stream length.

Returns

Stream

A stream for writing to the file on the server

OpenWrite(string, FtpDataType, long)

Opens the specified file for writing. Please call GetReply() after you have successfully transferred the file to read the "OK" command sent by the server and prevent stale data on the socket.

public virtual Stream OpenWrite(string path, FtpDataType type, long fileLen)

Parameters

path string

Full or relative path of the file

type FtpDataType

ASCII/Binary

fileLen long

Pass in a file length if known


-1 => File length is irrelevant, do not attempt to determine it

0 => File length is unknown, try to determine it

>0 => File length is KNOWN. No need to determine it

Returns

Stream

A stream for writing to the file on the server

OpenWriteInternal(string, FtpDataType, long, bool)

Internal routine

public virtual Stream OpenWriteInternal(string path, FtpDataType type, long fileLen, bool ignoreStaleData)

Parameters

path string
type FtpDataType
fileLen long
ignoreStaleData bool

Normally false. Obsolete API uses true

Returns

Stream

A stream for writing the file on the server

PurgeSuccessfulDownloads(IEnumerable<string>)

Remove successfully downloaded files.

protected void PurgeSuccessfulDownloads(IEnumerable<string> localFiles)

Parameters

localFiles IEnumerable<string>

PurgeSuccessfulUploads(IEnumerable<string>)

Remove successfully uploaded files.

protected void PurgeSuccessfulUploads(IEnumerable<string> remotePaths)

Parameters

remotePaths IEnumerable<string>

Rename(string, string)

Renames an object on the remote file system. Low level method that should NOT be used in most cases. Prefer MoveFile() and MoveDirectory(). Throws exceptions if the file does not exist, or if the destination file already exists.

public void Rename(string path, string dest)

Parameters

path string

The full or relative path to the object

dest string

The new full or relative path including the new name of the object

ResumeDownload(string, ref Stream, long, IOException)

Setup a resume on failure of download

protected bool ResumeDownload(string remotePath, ref Stream downStream, long offset, IOException ex)

Parameters

remotePath string
downStream Stream
offset long
ex IOException

Returns

bool

ResumeUpload(string, ref Stream, long, IOException)

Setup a resume on an upload failure

protected bool ResumeUpload(string remotePath, ref Stream upStream, long remotePosition, IOException ex)

Parameters

remotePath string
upStream Stream
remotePosition long
ex IOException

Returns

bool

SetDataType(FtpDataType)

protected void SetDataType(FtpDataType type)

Parameters

type FtpDataType

ASCII/Binary.

Remarks

This method doesn't do any locking to prevent recursive lock scenarios. Callers must do their own locking.

Exceptions

FtpCommandException

Thrown when a FTP Command error condition occurs.

FtpException

Thrown when a FTP error condition occurs.

SetFilePermissions(string, FtpPermission, FtpPermission, FtpPermission)

Modify the permissions of the given file/folder. Only works on *NIX systems, and not on Windows/IIS servers. Only works if the FTP server supports the SITE CHMOD command (requires the CHMOD extension to be installed and enabled). Throws FtpCommandException if there is an issue.

public void SetFilePermissions(string path, FtpPermission owner, FtpPermission group, FtpPermission other)

Parameters

path string

The full or relative path to the item

owner FtpPermission

The owner permissions

group FtpPermission

The group permissions

other FtpPermission

The other permissions

SetFilePermissions(string, int)

Modify the permissions of the given file/folder. Only works on *NIX systems, and not on Windows/IIS servers. Only works if the FTP server supports the SITE CHMOD command (requires the CHMOD extension to be installed and enabled). Throws FtpCommandException if there is an issue.

public void SetFilePermissions(string path, int permissions)

Parameters

path string

The full or relative path to the item

permissions int

The permissions in CHMOD format

SetModifiedTime(string, DateTime)

Changes the modified time of a remote file

public virtual void SetModifiedTime(string path, DateTime date)

Parameters

path string

The full path to the file

date DateTime

The new modified date/time value

SetWorkingDirectory(string)

Sets the work directory on the server

public void SetWorkingDirectory(string path)

Parameters

path string

The path of the directory to change to

TransferDirectory(string, FtpClient, string, FtpFolderSyncMode, FtpRemoteExists, FtpVerify, List<FtpRule>, Action<FtpProgress>)

Transfer the specified directory from the source FTP Server onto the remote FTP Server using the FXP protocol. You will need to create a valid connection to your remote FTP Server before calling this method. In Update mode, we will only transfer missing files and preserve any extra files on the remote FTP Server. This is useful when you want to simply transfer missing files from an FTP directory. Currently Mirror mode is not implemented. Only transfers the files and folders matching all the rules provided, if any. All exceptions during transfer are caught, and the exception is stored in the related FtpResult object.

public List<FtpResult> TransferDirectory(string sourceFolder, FtpClient remoteClient, string remoteFolder, FtpFolderSyncMode mode = FtpFolderSyncMode.Update, FtpRemoteExists existsMode = FtpRemoteExists.Skip, FtpVerify verifyOptions = FtpVerify.None, List<FtpRule> rules = null, Action<FtpProgress> progress = null)

Parameters

sourceFolder string

The full or relative path to the folder on the source FTP Server. If it does not exist, an empty result list is returned.

remoteClient FtpClient

Valid FTP connection to the destination FTP Server

remoteFolder string

The full or relative path to destination folder on the remote FTP Server

mode FtpFolderSyncMode

Only Update mode is currently implemented

existsMode FtpRemoteExists

If the file exists on disk, should we skip it, resume the download or restart the download?

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

rules List<FtpRule>

Only files and folders that pass all these rules are downloaded, and the files that don't pass are skipped. In the Mirror mode, the files that fail the rules are also deleted from the local folder.

progress Action<FtpProgress>

Provide a callback to track download progress.

Returns

List<FtpResult>

Returns a listing of all the remote files, indicating if they were downloaded, skipped or overwritten. Returns a blank list if nothing was transferred. Never returns null.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

TransferFile(string, FtpClient, string, bool, FtpRemoteExists, FtpVerify, Action<FtpProgress>, FtpProgress)

Transfer the specified file from the source FTP Server to the destination FTP Server using the FXP protocol. High-level API that takes care of various edge cases internally.

public FtpStatus TransferFile(string sourcePath, FtpClient remoteClient, string remotePath, bool createRemoteDir = false, FtpRemoteExists existsMode = FtpRemoteExists.Resume, FtpVerify verifyOptions = FtpVerify.None, Action<FtpProgress> progress = null, FtpProgress metaProgress = null)

Parameters

sourcePath string

The full or relative path to the file on the source FTP Server

remoteClient FtpClient

Valid FTP connection to the destination FTP Server

remotePath string

The full or relative path to destination file on the remote FTP Server

createRemoteDir bool

Indicates if the folder should be created on the remote FTP Server

existsMode FtpRemoteExists

If the file exists on disk, should we skip it, resume the download or restart the download?

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

progress Action<FtpProgress>

Provide a callback to track download progress.

metaProgress FtpProgress

Returns

FtpStatus

Returns a FtpStatus indicating if the file was transferred.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

TransferFileFXPInternal(string, FtpClient, string, bool, FtpRemoteExists, Action<FtpProgress>, FtpProgress)

Transfers a file from the source FTP Server to the destination FTP Server via the FXP protocol

protected bool TransferFileFXPInternal(string sourcePath, FtpClient remoteClient, string remotePath, bool createRemoteDir, FtpRemoteExists existsMode, Action<FtpProgress> progress, FtpProgress metaProgress)

Parameters

sourcePath string
remoteClient FtpClient
remotePath string
createRemoteDir bool
existsMode FtpRemoteExists
progress Action<FtpProgress>
metaProgress FtpProgress

Returns

bool

TransferServerFiles(List<FtpResult>, FtpClient, FtpRemoteExists, FtpVerify, Action<FtpProgress>, FtpListItem[])

Transfer each file

protected void TransferServerFiles(List<FtpResult> filesToTransfer, FtpClient remoteClient, FtpRemoteExists existsMode, FtpVerify verifyOptions, Action<FtpProgress> progress, FtpListItem[] remoteListing)

Parameters

filesToTransfer List<FtpResult>
remoteClient FtpClient
existsMode FtpRemoteExists
verifyOptions FtpVerify
progress Action<FtpProgress>
remoteListing FtpListItem[]

UploadBytes(byte[], string, FtpRemoteExists, bool, Action<FtpProgress>)

Uploads the specified byte array as a file onto the server. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks.

public FtpStatus UploadBytes(byte[] fileData, string remotePath, FtpRemoteExists existsMode = FtpRemoteExists.Overwrite, bool createRemoteDir = false, Action<FtpProgress> progress = null)

Parameters

fileData byte[]

The full data of the file, as a byte array

remotePath string

The full or relative path to the file on the server

existsMode FtpRemoteExists

What to do if the file already exists? Skip, overwrite or append? Set this to NoCheck for fastest performance but only if you are SURE that the files do not exist on the server.

createRemoteDir bool

Create the remote directory if it does not exist. Slows down upload due to additional checks required.

progress Action<FtpProgress>

Provide a callback to track upload progress.

Returns

FtpStatus

UploadDirectory(string, string, FtpFolderSyncMode, FtpRemoteExists, FtpVerify, List<FtpRule>, Action<FtpProgress>)

Uploads the specified directory onto the server. In Mirror mode, we will upload missing files, and delete any extra files from the server that are not present on disk. This is very useful when publishing an exact copy of a local folder onto an FTP server. In Update mode, we will only upload missing files and preserve any extra files on the server. This is useful when you want to simply upload missing files to a server. Only uploads the files and folders matching all the rules provided, if any. All exceptions during uploading are caught, and the exception is stored in the related FtpResult object.

public List<FtpResult> UploadDirectory(string localFolder, string remoteFolder, FtpFolderSyncMode mode = FtpFolderSyncMode.Update, FtpRemoteExists existsMode = FtpRemoteExists.Skip, FtpVerify verifyOptions = FtpVerify.None, List<FtpRule> rules = null, Action<FtpProgress> progress = null)

Parameters

localFolder string

The full path of the local folder on disk that you want to upload. If it does not exist, an empty result list is returned.

remoteFolder string

The full path of the remote FTP folder to upload into. It is created if it does not exist.

mode FtpFolderSyncMode

Mirror or Update mode, as explained above

existsMode FtpRemoteExists

If the file exists on disk, should we skip it, resume the upload or restart the upload?

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

rules List<FtpRule>

Only files and folders that pass all these rules are downloaded, and the files that don't pass are skipped. In the Mirror mode, the files that fail the rules are also deleted from the local folder.

progress Action<FtpProgress>

Provide a callback to track upload progress.

Returns

List<FtpResult>

Returns a listing of all the remote files, indicating if they were downloaded, skipped or overwritten. Returns a blank list if nothing was transferred. Never returns null.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

UploadDirectoryFiles(List<FtpResult>, FtpRemoteExists, FtpVerify, Action<FtpProgress>, FtpListItem[])

Upload all the files within the main directory

protected void UploadDirectoryFiles(List<FtpResult> filesToUpload, FtpRemoteExists existsMode, FtpVerify verifyOptions, Action<FtpProgress> progress, FtpListItem[] remoteListing)

Parameters

filesToUpload List<FtpResult>
existsMode FtpRemoteExists
verifyOptions FtpVerify
progress Action<FtpProgress>
remoteListing FtpListItem[]

UploadFile(string, string, FtpRemoteExists, bool, FtpVerify, Action<FtpProgress>)

Uploads the specified file directly onto the server. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks.

public FtpStatus UploadFile(string localPath, string remotePath, FtpRemoteExists existsMode = FtpRemoteExists.Overwrite, bool createRemoteDir = false, FtpVerify verifyOptions = FtpVerify.None, Action<FtpProgress> progress = null)

Parameters

localPath string

The full or relative path to the file on the local file system

remotePath string

The full or relative path to the file on the server

existsMode FtpRemoteExists

What to do if the file already exists? Skip, overwrite or append? Set this to NoCheck for fastest performance but only if you are SURE that the files do not exist on the server.

createRemoteDir bool

Create the remote directory if it does not exist. Slows down upload due to additional checks required.

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

progress Action<FtpProgress>

Provide a callback to track download progress.

Returns

FtpStatus

FtpStatus flag indicating if the file was uploaded, skipped or failed to transfer.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

UploadFileFromFile(string, string, bool, FtpRemoteExists, bool, bool, FtpVerify, Action<FtpProgress>, FtpProgress)

Upload a local file to a remote file

protected FtpStatus UploadFileFromFile(string localPath, string remotePath, bool createRemoteDir, FtpRemoteExists existsMode, bool fileExists, bool fileExistsKnown, FtpVerify verifyOptions, Action<FtpProgress> progress, FtpProgress metaProgress)

Parameters

localPath string
remotePath string
createRemoteDir bool
existsMode FtpRemoteExists
fileExists bool
fileExistsKnown bool
verifyOptions FtpVerify
progress Action<FtpProgress>
metaProgress FtpProgress

Returns

FtpStatus

Exceptions

FtpException

UploadFileInternal(Stream, string, string, bool, FtpRemoteExists, bool, bool, Action<FtpProgress>, FtpProgress)

Upload the given stream to the server as a new file. Overwrites the file if it exists. Writes data in chunks. Retries if server disconnects midway.

protected FtpStatus UploadFileInternal(Stream fileData, string localPath, string remotePath, bool createRemoteDir, FtpRemoteExists existsMode, bool fileExists, bool fileExistsKnown, Action<FtpProgress> progress, FtpProgress metaProgress)

Parameters

fileData Stream
localPath string
remotePath string
createRemoteDir bool
existsMode FtpRemoteExists
fileExists bool
fileExistsKnown bool
progress Action<FtpProgress>
metaProgress FtpProgress

Returns

FtpStatus

UploadFiles(IEnumerable<FileInfo>, string, FtpRemoteExists, bool, FtpVerify, FtpError, Action<FtpProgress>, List<FtpRule>)

Uploads the given file paths to a single folder on the server. All files are placed directly into the given folder regardless of their path on the local filesystem. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks. Faster than uploading single files with since it performs a single "file exists" check rather than one check per file.

public List<FtpResult> UploadFiles(IEnumerable<FileInfo> localFiles, string remoteDir, FtpRemoteExists existsMode = FtpRemoteExists.Overwrite, bool createRemoteDir = true, FtpVerify verifyOptions = FtpVerify.None, FtpError errorHandling = FtpError.None, Action<FtpProgress> progress = null, List<FtpRule> rules = null)

Parameters

localFiles IEnumerable<FileInfo>

The full or relative paths to the files on the local file system. Files can be from multiple folders.

remoteDir string

The full or relative path to the directory that files will be uploaded on the server

existsMode FtpRemoteExists

What to do if the file already exists? Skip, overwrite or append? Set this to NoCheck for fastest performance, but only if you are SURE that the files do not exist on the server.

createRemoteDir bool

Create the remote directory if it does not exist.

verifyOptions FtpVerify

Sets if checksum verification is required for a successful upload and what to do if it fails verification (See Remarks)

errorHandling FtpError

Used to determine how errors are handled

progress Action<FtpProgress>

Provide an implementation of IProgress to track upload progress.

rules List<FtpRule>

Only files that pass all these rules are uploaded, and the files that don't pass are skipped.

Returns

List<FtpResult>

Returns a listing of all the local files, indicating if they were uploaded, skipped or overwritten. Returns a blank list if nothing was transferred. Never returns null.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

UploadFiles(IEnumerable<string>, string, FtpRemoteExists, bool, FtpVerify, FtpError, Action<FtpProgress>, List<FtpRule>)

Uploads the given file paths to a single folder on the server. All files are placed directly into the given folder regardless of their path on the local filesystem. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks. Faster than uploading single files with since it performs a single "file exists" check rather than one check per file.

public List<FtpResult> UploadFiles(IEnumerable<string> localPaths, string remoteDir, FtpRemoteExists existsMode = FtpRemoteExists.Overwrite, bool createRemoteDir = true, FtpVerify verifyOptions = FtpVerify.None, FtpError errorHandling = FtpError.None, Action<FtpProgress> progress = null, List<FtpRule> rules = null)

Parameters

localPaths IEnumerable<string>

The full or relative paths to the files on the local file system. Files can be from multiple folders.

remoteDir string

The full or relative path to the directory that files will be uploaded on the server

existsMode FtpRemoteExists

What to do if the file already exists? Skip, overwrite or append? Set this to NoCheck for fastest performance, but only if you are SURE that the files do not exist on the server.

createRemoteDir bool

Create the remote directory if it does not exist.

verifyOptions FtpVerify

Sets verification type and what to do if verification fails (See Remarks)

errorHandling FtpError

Used to determine how errors are handled

progress Action<FtpProgress>

Provide an implementation of IProgress to track upload progress.

rules List<FtpRule>

Only files that pass all these rules are uploaded, and the files that don't pass are skipped.

Returns

List<FtpResult>

Returns a listing of all the local files, indicating if they were uploaded, skipped or overwritten. Returns a blank list if nothing was transferred. Never returns null.

Remarks

If verification is enabled (All options other than None) the file will be verified against the source using the verification methods specified by FtpVerifyMethod in the client config.
If only OnlyVerify is set then the return of this method depends on both a successful transfer & verification.
Additionally, if any verify option is set and a retry is attempted the existsMode will automatically be set to Overwrite. If Throw is set and Throw is not set, then individual verification errors will not cause an exception to propagate from this method.

UploadStream(Stream, string, FtpRemoteExists, bool, Action<FtpProgress>)

Uploads the specified stream as a file onto the server. High-level API that takes care of various edge cases internally. Supports very large files since it uploads data in chunks.

public FtpStatus UploadStream(Stream fileStream, string remotePath, FtpRemoteExists existsMode = FtpRemoteExists.Overwrite, bool createRemoteDir = false, Action<FtpProgress> progress = null)

Parameters

fileStream Stream

The full data of the file, as a stream

remotePath string

The full or relative path to the file on the server

existsMode FtpRemoteExists

What to do if the file already exists? Skip, overwrite or append? Set this to NoCheck for fastest performance but only if you are SURE that the files do not exist on the server.

createRemoteDir bool

Create the remote directory if it does not exist. Slows down upload due to additional checks required.

progress Action<FtpProgress>

Provide a callback to track upload progress.

Returns

FtpStatus

VerifyFXPTransfer(string, FtpClient, string)

Verify an FXP file transfer

protected bool VerifyFXPTransfer(string sourcePath, FtpClient fxpDestinationClient, string remotePath)

Parameters

sourcePath string
fxpDestinationClient FtpClient
remotePath string

Returns

bool

Exceptions

ArgumentException
ArgumentNullException

VerifyTransfer(string, string)

Verify a file transfer

protected bool VerifyTransfer(string localPath, string remotePath)

Parameters

localPath string
remotePath string

Returns

bool

Exceptions

ArgumentException