+2 votes

I wanted to know if you have working example for FTPS to upload files we will be getting via stream.

On your web site I do see that your FTP library supports .NET Streams - read from and write to on the fly. However, I don't see any working example or help regarding this.

by

1 Answer

0 votes
 
Best answer

Streams are of course supported by FTP .NET client, both uploading from a Stream and downloading to a Stream.

Here's the sample of uploading file from a .NET stream. We use FileStream in this particular case, but any .NET Stream can by used. For example MemoryStream:

using(Ftp ftp = new Ftp())
{
    ftp.ConnectSSL("ftp.example.com");
    ftp.Login("user", "password");

    using (Stream destination = File.Create("c:\\june2014.csv"))
    {
        ftp.Download("\\reports\\june2014.csv", destination);
        destination.Close();
    }
    ftp.Close();
}

Here's the sample of downloading file from a remote FTP server directly in to .NET stream. Again we use FileStream here, but of course any .NET stream can be used.

using(Ftp ftp = new Ftp())
{
    ftp.ConnectSSL("ftp.example.com");
    ftp.Login("user", "password");

    using (Stream source = File.OpenRead("c:\\results.csv"))
    {
        ftp.Upload("\\reports\\results.csv", source);
        source.Close();
    }
    ftp.Close();
}
by (297k points)
edited by
...