Skip to content

SSH.Put

Andrew Lambert edited this page Nov 26, 2022 · 5 revisions

SSH.Put

Method signature

 Protected Function Put(Optional Session As SSH.Session, URL As String, Length As UInt32 = 0, Overwrite As Boolean = False) As SSH.SSHStream

Parameters

Name Type Comment
Session Session Optional. If specified, an active SSH session to use.
URL String The fully qualified URL to upload to.
Length UInt32 The total number of bytes which will be uploaded. Optional for SFTP, mandatory for SCP
Overwrite Boolean Optional. If True, then the remote file will be overwritten if it exists.

Return value

An object that implements the SSHStream interface, to which the upload data can be written.

Remarks

This convenience method prepares an upload using SFTP or SCP (specified in the URL). If the Session parameter is specified then only the path part of the URL is used.

Example

This example specifies everything in the URL

  Dim writer As SSHStream = SSH.Put("sftp://username:password@ssh.example.com:2222/pub/file.zip")
  Dim reader As BinaryStream = BinaryStream.Open(SpecialFolder.Desktop.Child("file.zip"))
  Do Until reader.EOF
    writer.Write(reader.Read(1024 * 64))
  Loop
  reader.Close
  writer.Close

This example uses an existing session.

  Dim session As SSH.Session = SSH.Connect("ssh.example.com", 2222, "username", "password")
  Dim writer As SSHStream = SSH.Put(session, "sftp:///pub/file.zip") ' Note the triple /
  Dim reader As BinaryStream = BinaryStream.Open(SpecialFolder.Desktop.Child("file.zip"))
  Do Until reader.EOF
    writer.Write(reader.Read(1024 * 64))
  Loop
  reader.Close
  writer.Close
Clone this wiki locally