SSH.Put - charonn0/RB-libssh2 GitHub Wiki
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:[email protected]: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