Version: 4.5.0.0
Easily add comprehensive, secure FTP to any .NET application or service.

MGet Code Example

The following example demonstrates an FTP session in which multiple files are downloaded from the server. In this example, all text files in a directory (including sub-directories) are retrieved, except for a single, specified file.

< Back to all samples for PowerTCP FTP for .NET 

private void mget()
{
    //Get text files in a directory
    ftp1.Session.RemoteEndPoint.HostNameOrAddress = myServer;
    ftp1.Session.Username = myUsername;
    ftp1.Session.Password = myPassword;
    ftp1.Connect();
    ftp1.Authenticate();

    //Get a list of txt files to get
    List<ListEntry> filesToGet = ftp1.ListDirectoryTree("MyTextFiles""*.txt"true);

    //Tailor the list to not include a specific file
    foreach (ListEntry entry in filesToGet)
    {
        if (entry.Name == "not_me.txt")
        {
            filesToGet.Remove(entry);
            break;
        }
    }

    //Get the files
    string workingDirectory = ftp1.GetDirectory();
    ftp1.Get(filesToGet, workingDirectory + "/MyTextFiles", myLocalDirectory, Synchronize.Off);

    //Logout
    ftp1.Close();
}