I'm not sure what do you exactly mean with "packaging a file". But once you have a filestream, you can:
- either copy the stream to a file on local disc or on network folder using the system CopyTo method,
- or copy the stream to an FTP server using the Rebex FTP/SSL component.
Here is an example for both ways:
using System;
using System.IO;
using Rebex.Net;
namespace Rebex.Examples
{
class Program
{
static void Main(string[] args)
{
bool copyUsingFtp = true;
// create a source stream
// (we obtain it simply by opening a file, it woud be more complicated in your application)
using (FileStream src = File.OpenRead(@"c:\temp\file1.txt"))
{
// copy the stream content to the destination...
if (copyUsingFtp)
// ... etiher using FTP ...
FtpFile(src, "/temp/copied_file.txt");
else
// ... or using system file copy
CopyFile(src, @"c:\temp\copied_file.txt");
}
}
private static void CopyFile(FileStream src, string dstFilename)
{
// create stream for destination file (in "overwrite" mode)
using (FileStream dst = new FileStream(dstFilename, FileMode.Create))
{
// copy the stream using system CopyTo method (new in .NET 4.0)
src.CopyTo(dst);
}
}
private static void FtpFile(FileStream src, string dstFilename)
{
// create a Rebex FTP/SSL client object
using (Ftp client = new Ftp())
{
// connect and login to the remote FTP server
client.Connect("ftpserveraddress.com");
client.Login("username", "password");
// upload the source stream to the FTP server
client.PutFile(src, dstFilename);
// disconnect from the FTP server
client.Disconnect();
}
}
}
}
Note: The CopyTo method is new in .NET 4.0. For older versions of .NET framework you can copy streams manually e.g according the following article.