Resuming file transfer with the Ultimate SFTP component

Resume Upload File

For some reason, your file upload has been interrupted and you wish to resume the interrupted file upload. It is very easy to do that, just pass the path of the local file and the path of the remote file to the ResumeUploadFile method. If you wish to resume file upload from a stream, use this version of the ResumeUploadFile method.

The client class will check if the destination file actually exists. If so it will compare the remote file size against the local file size. If they are equal, the client will skip the transfer. If the remote file size is greater than the local file size or the remote file does not exist, the library will recreate the target file and copy the whole local file to the remote folder. Otherwise, the file transfer is resumed from the end position of the remote file.

The following steps will illustrate how to use that ResumeUploadFile method:

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

...

// Create a new Sftp instance.
Sftp client = new Sftp();

// Connect to the SFTP server.
client.Connect("localhost");

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

// ...

// Resume uploading local file 'c:\test.dat' to '/test.dat'.
client.ResumeUploadFile("c:\\test.dat", "/test.dat");

// ...

// Disconnect.
client.Disconnect();
Imports System.IO
Imports ComponentPro.Net

...

' Create a new Sftp instance.
Dim client As New Sftp()

' Connect to the SFTP server.
client.Connect("localhost")

' Authenticate.
client.Authenticate("test", "test")

' ...

' Resume uploading local file 'c:\test.dat' to '/test.dat'.
client.ResumeUploadFile("c:\test.dat", "/test.dat")

' ...

' Disconnect.
client.Disconnect()

Resume Download File

In addition to resuming file upload, we may also need to resume file download in some cases. Interuption due to network issues is an example. If you set the ReconnectionMaxRetries property of the Ftp class to a value other than 0, the client automatically reconnect to the server and resume the transfer. In case we want to manually resume our download, ResumeUploadFile method is the one we should use. Here we will explore how that method works with the following example:

using ComponentPro.Net;

...

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

// Connect to the SFTP server.
client.Connect("localhost");

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

// ...

// Resume downloading remote file '/test.dat' to 'c:\test.dat'
client.ResumeDownloadFile("/test.dat", "c:\\test.dat");
// If you also need to get the remote file length, use the following code.
//long remoteFileSize;
//client.ResumeDownloadFile("/test.dat", "c:\\test.dat", out remoteFileSize);
//Console.WriteLine("File size before uploading: {0}", remoteFileSize);

// ...

// Disconnect.
client.Disconnect();
Imports ComponentPro.Net

...

' Create a new class instance.
Dim client As New Sftp()

' Connect to the SFTP server.
client.Connect("localhost")

' Authenticate.
client.Authenticate("test", "test")

' ...

' Resume downloading remote file '/test.dat' to 'c:\test.dat'
client.ResumeDownloadFile("/test.dat", "c:\test.dat")
' If you also need to get the remote file length, use the following code.
'long remoteFileSize;
'client.ResumeDownloadFile("/test.dat", "c:\\test.dat", out remoteFileSize);
'Console.WriteLine("File size before uploading: {0}", remoteFileSize);

' ...

' Disconnect.
client.Disconnect()

45-Day Money Back Guarantee

We will refund your full money in 45 days
if you are not satisfied with our products

Buy Now

Dont miss out Get update on new articles and other opportunities