To download files and directories on an SFTP server to a ZIP file, you will need to add reference to UltimateZip.dllassembly. The UltimateZip is available for download at: UltimateZip Download Page For more information about this product, visit its home page.
The following example code shows you how to connect to an SFTP server and download files to a ZIP file on-the-fly.
C#:
// Connect to an SFTP file system.
Sftp sftp = new Sftp();
sftp.Connect("componentpro.com", 22);
sftp.Authenticate("test", "test");
// Create a new zip file.
Zip zip = new Zip();
zip.Create("test.zip");
// Add all remote files to the newly created archive.
// This operation directly adds files to the ZIP file, no temporary files created.
// Use this
zip.AddFiles(sftp, "", (IFileInfo[])null, "", new TransferOptions());
// or this
//sftp.DownloadFiles("", (IFileInfo[])null, zip, "", new TransferOptions());
// Close all used resources.
zip.Close();
sftp.Disconnect();
VB.NET:
' Connect to an SFTP file system.
Dim sftp As New Sftp()
sftp.Connect("componentpro.com", 22)
sftp.Authenticate("test", "test")
' Create a new zip file.
Dim zip As New Zip()
zip.Create("test.zip")
' Add all remote files to the newly created archive.
' This operation directly adds files to the ZIP file, no temporary files created.
' Use this
zip.AddFiles(sftp, "", CType(Nothing, IFileInfo()), "", New TransferOptions())
' or this
'sftp.DownloadFiles("", (IFileInfo[])null, zip, "", new TransferOptions());
' Close all used resources.
zip.Close()
sftp.Disconnect()