• Loading...
ComponentPro UltimateSftp

Upload and download a file

Language Filter: AllSend comments on this topic to ComponentPro

Using the UploadFile method to store and DownloadFile method to download a single file. Both methods have overloads that allow you to upload and download a file from and to memory instead of disk. See the "Upload data from a stream" and "Downloading data to a stream" for more information.

The example below shows you how to use the UploadFile and DownloadFile methods to upload and download a single file:

using System;
using ComponentPro.IO;
using ComponentPro.Net;

...

// Create a new class instance.
Scp client = new Scp();

try
{
    // Connect to the SCP server. 
    client.Connect("localhost");

    // Authenticate. 
    client.Authenticate("test", "test");

    // ... 
 
    // Upload file "c:\test.zip". 
    client.UploadFile("c:\\test.zip", "test.zip");

    // Download the "test.zip" file. 
    client.DownloadFile("test.zip", "c:\\test_download.zip");

    // ... 
 
    // Disconnect. 
    client.Disconnect();
}
catch (ScpException exc)
{
    Console.WriteLine("An error occurred: Code: {0}, Message: {1}", exc.Status, exc.Message);

    if (client.State != RemoteFileSystemState.Disconnected)
        client.Disconnect();
}