-
-
Notifications
You must be signed in to change notification settings - Fork 4
SCP Examples
Andrew Lambert edited this page Nov 26, 2022
·
4 revisions
SCP is a protocol for reading and writing files on a server over SSH. SCP is considered a legacy protocol, and lacks many of the features of its replacement SFTP. SCP operations are performed using the SSH.SCPStream class (a subclass of SSH.Channel.)
This example downloads a file over SCP:
Dim session As SSH.Session = SSH.Connect("ssh.example.com", 22, "username", "password")
Dim download As New SSH.SCPStream(session, "/home/user/file.txt")
Dim local As BinaryStream = BinaryStream.Create(SpecialFolder.Desktop.Child("file.txt"))
Do Until download.EOF
If download.PollReadable() Then
local.Write(download.Read(download.BytesReadable))
End If
Loop
download.Close
local.Close
This example uploads a file over SCP. The size of the upload must be specified in advance and must be correct:
Dim session As SSH.Session = SSH.Connect("ssh.example.com", 22, "username", "password")
Dim local As FolderItem = SpecialFolder.Desktop.Child("file.txt")
Dim upload As New SSH.SCPStream(session, "/home/user/" + local.Name, local.Permissions, local.Length, 0, 0)
Dim stream As BinaryStream = BinaryStream.Open(local)
Do Until stream.EOF
If upload.PollWriteable() Then
upload.Write(stream.Read(upload.BytesWriteable))
End If
Loop
upload.Close
stream.Close
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2018-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.