• Loading...
ComponentPro UltimateZip

Working with SFTP File System

Language Filter: AllSend comments on this topic to ComponentPro

The following examples demonstrate how to add files from an SFTP server to an archive and extract files from an archive onto an SFTP server.

Adding files on an SFTP server to a Zip file

using ComponentPro.IO;
using ComponentPro.Net;
using ComponentPro.Compression;

...

// Connect to an SFTP file system.
Sftp sftp = new Sftp();
sftp.Connect("demo.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, "", false, null, "", new TransferOptions()); 
// or this 
// sftp.DownloadFiles("", false, null, zip, "", new TransferOptions()); 
 
// Close all used resources.
zip.Close();
sftp.Disconnect();

Extracting files from a Zip file onto an SFTP server

using System;
using System.Collections.Generic;
using System.Text;
using ComponentPro.IO;
using ComponentPro.Net;
using ComponentPro.Compression;

...

// Connect to an SFTP file system.
Sftp sftp = new Sftp();
sftp.Connect("demo.componentpro.com", 22);
sftp.Authenticate("test", "test");

// Open an existing zip file.
Zip zip = new Zip();

zip.Open(@"c:\test.zip");

// Extract and upload all files within the archive to the SFTP server. 
// This operation directly uploads files to the SFTP server, no temporary files created.
zip.ExtractAll(sftp, "", FileOverwriteMode.Overwrite);

// Close all used resources.
zip.Close();
sftp.Disconnect();