In release R1 2012, we introduced new API for uploading and downloading multiple files. In this blog post, we are going to explain how to use the new Download and Upload methods. The usage is illustrated on the Download method, but the same principles can be applied for Upload as well.
In the following examples,
client is an instance of either Ftp or Sftp object*:
Sftp client = new Sftp(); client.Connect(server, port); client.Login(username, password);
Let's consider following directory structure on the server:
/data/web/page1.html /data/web/page2.html /data/web/images /data/web/images/image1.jpeg /data/web/images/image2.jpeg
1) Download a single file
To download the "/data/web/page1.html" file into "C:\data", do this:
This will download the file into:
2) Download directory with its content
If you want to download the directory "/data/web" with all its content (including "images" subdirectory), you can simply write:
This will create this local structure:
C:\data\web\page1.html C:\data\web\page2.html C:\data\web\images\ C:\data\web\images\image1.jpeg C:\data\web\images\image2.jpeg
The whole directory "web" is downloaded into "C:\data".
3) Download only the contents of a directory
If you want to transfer only the contents of directory "/data/web" directly into "C:\data", without creating the directory "web" locally, you can do it easily like this:
Local structure will be:
C:\data\page1.html C:\data\page2.html C:\data\images\ C:\data\images\image1.jpeg C:\data\images\image2.jpeg
Note: The "* **" wildcard stands for any file or directory name, so "/data/web/ *" means any file or directory from "/data/web" directory.
To learn how to filter specific files/directories only, please visit our Advanced Download and Upload with SFTP and FTP components blog post. We also discuss usage of wildcards and the optional
TraversalMode argument there.
*Our Rebex ZIP component also offers the new multi-file API. The ZipArchive.Add and ZipArchive.Extract methods can be used in the same way as Ftp/Sftp Upload and Download methods respectively.