-
-
Notifications
You must be signed in to change notification settings - Fork 4
SFTP Examples
Andrew Lambert edited this page Oct 26, 2020
·
17 revisions
SFTP is a protocol for managing files on a server over SSH.
This example downloads a file over SFTP. For extended features like reading file metadata refer to the SFTPStream class:
Dim session As SSH.Session = SSH.Connect("ssh://user:[email protected]/")
Dim sftp As New SSH.SFTPSession(session)
Dim reader As SSHStream = sftp.Get("file.txt")
Dim writer As BinaryStream = BinaryStream.Create(SpecialFolder.Desktop.Child("file.txt"))
Do Until reader.EOF
writer.Write(reader.Read(1024))
Loop
reader.Close
writer.Close
This example uploads a file over SFTP. For extended features like appending to an existing file refer to the SFTPStream class:
Dim session As SSH.Session = SSH.Connect("ssh://user:[email protected]/")
Dim sftp As New SSH.SFTPSession(session)
Dim writer As SSHStream = sftp.Put("file.txt")
Dim reader As BinaryStream = BinaryStream.Open(SpecialFolder.Desktop.Child("file.txt"))
Do Until reader.EOF
writer.Write(reader.Read(1024))
Loop
reader.Close
writer.Close
This example lists the names of files/subdirectories in a remote directory using SFTP. For extended features like getting file sizes refer to the SFTPDirectory class:
Dim session As SSH.Session = SSH.Connect("ssh://user:[email protected]/")
Dim sftp As New SSH.SFTPSession(session)
Dim names() As String
Dim lister As SSHStream = sftp.ListDirectory("/path/to/dir/")
Do Until lister.EOF
names.Append(lister.Read(1024))
Loop
lister.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.