IPWorks SSH 2020 Kotlin Edition

Questions / Feedback?

Download Method

Download a RemoteFile using SFTP or SCP.

Syntax

public fun download(): String?

Remarks

This method downloads the remote file specified by RemoteFile to the local file specified by LocalFile. The StartTransfer, Transfer, and EndTransfer events provide details about the individual file transfers. If the LocalFile property is "" (empty string) then the file data will be available through the Transfer event.

This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.

When the operation completes the DownloadComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the DownloadComplete event to determine the result.

If there is no SSH session in place, one is automatically created by the component first.

This method is only applicable when ChannelType is set to cstSftp or cstScp.

Set RemoteFile to the name of the file to download before calling this method. If RemoteFile only specifies a filename it will be downloaded from the path specified by RemotePath. RemoteFile may also be set to an absolute path.

The file will be downloaded to the stream specified (if any) by SetDownloadStream. If a stream is not specified and LocalFile is set the file will be saved to the specified location.

Code Example


SSHPlexControl.Localfile = "C:\localfile.txt";
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Download();

// Use Path in RemoteFile
SSHPlexControl.Localfile = "C:\localfile2.txt";
SSHPlexControl.RemoteFile = "folder/remotefile2.txt";
string operationId = SSHPlexControl.Download();

Resuming Downloads

The component also supports resuming failed downloads by using the StartByte property. If a download is interrupted or canceled, set StartByte to the appropriate offset before calling this method to resume the download.


string localFile = "C:\localfile.txt";
SSHPlexControl.Localfile = localFile;
SSHPlexControl.RemoteFile = "remotefile.txt";
string operationId = SSHPlexControl.Download();

// Cancel Download using the CancelOperation method
SSHPlexControl.CancelOperation(operationId);

// Get the size of the partially downloaded temp file and set StartByte
SSHPlexControl.StartByte = new FileInfo(localFile).Length;

// Resume download
string operationId = SSHPlexControl.Download();

Downloading Multiple Files Using a Filemask

Note: Using a filemask for downloads is only applicable when ChannelType is set to cstScp. To download files matching a filemask set RemoteFile to a filemask. The path may be specified as part of the value in RemoteFile or may be set separately in RemotePath. LocalFile should be set to a local directory where files will be downloaded. When Download is called all matching files are downloaded. See RemoteFile for more information.

Copyright (c) 2021 /n software inc. - All rights reserved.
IPWorks SSH 2020 Kotlin Edition - Version 20.0 [Build 7941]