Upload Method

Upload a file specified by LocalFile using SCP or SFTP.

Syntax

public String upload();

Remarks

This method Uploads the local file specified by LocalFile to the remote file specified by RemoteFile. 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 UploadComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the UploadComplete 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 LocalFile to the name of the file to upload before calling this method. If SetUploadStream is used to set an upload stream the data to upload is taken from the stream instead.

RemoteFile should be set to either a relative or absolute path. If RemoteFile is not an absolute path it will be uploaded relative to RemotePath.

Code Example


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

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

Resuming Uploads

The class also supports resuming failed uploads by using the StartByte property. If an upload is interrupted or canceled, set StartByte to the appropriate offset before calling this method to resume the upload.


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

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

// Get the size of the partially uploaded temp file and set StartByte
SSHPlexControl.StartByte = SSHPlexControl.FileAttributes.Size;

// Resume upload
string operationId = SSHPlexControl.Upload();

Copyright (c) 2023 /n software inc. - All rights reserved.
IPWorks SSH 2020 Java Edition - Version 20.0 [Build 8501]