0 votes
by (180 points)

Is it possible to take a File (CSV) from Stream , ZIp it with a password, then send it to a SFTP site without a file being actually being created?

1 Answer

+1 vote
by (73.6k points)

Yes, it is very easy using Rebex components:

// prepare input data
var inputStream = new MemoryStream(Encoding.ASCII.GetBytes("This is test data."));

// prepare ZIP stream
var zipStream = new MemoryStream();
using (var zip = new ZipArchive(zipStream, ArchiveStreamCloseMode.LeaveOpen))
{
    // set password
    zip.Password = "top-secret";

    // add input data
    zip.AddFile(inputStream, "data.txt");
}

// connect to SFTP and log in 
var client = new Sftp();
client.Connect(sftpHost, sftpPort);
client.Login(sftpUser, sftpPassword);

// upload ZIP stream (from the beginning)
zipStream.Position = 0;
client.PutFile(zipStream, "/data/secret.zip");

All is done in memory, without need to create any temporary file on disk.

by (180 points)
looks great, thanks for the fast response.
...