To upload multiple files (e.g. all ".dat" files), use the Upload methods. The most used Upload method overload just needs two parameters. The first one is the path to the local directory and the second one is the path to the remote directory.
using System; using ComponentPro.IO; using ComponentPro.Net; ... // Create a new class instance. Ftp client = new Ftp(); // Connect to the FTP server. client.Connect("localhost"); // Authenticate. client.Authenticate("test", "test"); // ... // Upload all files and subdirectories from local folder 'c:\temp' to the remote dir '/temp' client.Upload("c:\\temp", "/temp"); // Upload all directories, subdirectories, and files that match the specified search pattern from local folder 'c:\myfolder2' to remote folder '/myfolder2'. client.Upload("c:\\myfolder2", "/myfolder2", "*.cs"); // or you can simply put wildcard masks in the source path, our component will automatically parse it. // upload all *.css files from local folder 'c:\myfolder2' to remote folder '/myfolder2'. client.Upload("c:\\myfolder2\\*.css", "/myfolder2"); // Upload *.cs and *.vb files from local folder 'c:\myfolder2' to remote folder '/myfolder2'. client.Upload("c:\\myfolder2\\*.cs;*.vb", "/myfolder2"); // ... // Disconnect. client.Disconnect();
To upload just some specific files and directories, use the Upload method overloads that have localFilesToTransfer or sourceFilesToTransfer parameter like this Upload overload.
using (Ftp ftp = new Ftp()) { // Connect to the FTP server. ftp.Connect("localhost"); // Authenticate. ftp.Authenticate("test", "test"); string[] filesAndFoldersToUpload = new string[] { @"C:\data", @"C:\myfolder\content", @"C:\myfiles\file1", @"C:\myfiles\file2" }; ftp.Upload( filesAndFoldersToUpload, // List of files and folders to upload. "/dest", // The remote directory on the FTP server. new TransferOptions() ); }