FTP uploading files using patterns
Uploading files using patters is a unique feature of our FTP component. It allows you fast upload of files of certain types.
Here’s the sample that uploads all text files (*.txt) files from C drive, to newly created ‘Uploads’ folder on FTP server. The search includes all child folders recursively – note the true parameter in LocalSearchOptions constructor. Ftp component is going to create all necessary folders on the remote FTP server for you.
Upload using wildcard pattern
// C# using (Ftp ftp = new Ftp()) { ftp.Connect("ftp.example.com"); // or ConnectSSL ftp.CreateFolder("Uploads"); LocalSearchOptions options = new LocalSearchOptions("*.txt", true); ftp.UploadFiles("Uploads", @"c:\", options); ftp.Close(); }
' VB.NET Using ftp As New Ftp() ftp.Connect("ftp.example.com") ' or ConnectSSL ftp.CreateFolder("Uploads") Dim options As New LocalSearchOptions("*.txt", True) ftp.UploadFiles("Uploads", "c:\", options) ftp.Close() End Using
Upload using regex pattern
You can also use LocalSearchOptions.UseRegexMatch method, if you want to use regex patterns:
// C# using (Ftp ftp = new Ftp()) { ftp.Connect("ftp.example.com"); // or ConnectSSL ftp.CreateFolder("Uploads"); LocalSearchOptions options = new LocalSearchOptions(); options.UseRegexMatch(@"^.*$", @"^.*\.txt$", true); ftp.UploadFiles("Uploads", @"c:\", options); ftp.Close(); }
' VB.NET Using ftp As New Ftp() ftp.Connect("ftp.example.com") ' or ConnectSSL ftp.CreateFolder("Uploads") Dim options As New LocalSearchOptions() options.UseRegexMatch("^.*$", "^.*\.txt$", True) ftp.UploadFiles("Uploads", "c:\", options) ftp.Close() End Using
January 9th, 2017 at 10:05
How can I use UploadFiles to the root folder on the server?
I tried:
client.UploadFiles(“.”, this.LocalFolder, new LocalSearchOptions(“*.jpg”, false));
and
client.UploadFiles(“/”, this.LocalFolder, new LocalSearchOptions(“*.jpg”, false));
But both give an error, stating that the target folder on the server does not exist.
Regards,
Michael
January 9th, 2017 at 10:26
@Michael
Have you tried getting the current folder name just after you logged in:
Your account root folder may be not the same as the server folder (e.g. “/ftp/michael/”).
July 22nd, 2017 at 11:14
how to upload a single and particular file……?
July 23rd, 2017 at 07:55
@Pawan,
You just need to use Upload method. There are several overloads of this method, that allow to uploading byte array, stream, or simply uploading file from disk:
http://www.limilabs.com/blog/upload-file-using-ftp