SFTP sample code

I have occasion to need to FTP data in order to integrate it. Usually I use the FTP components that come with .NET, but they don't handle SFTP. It's a changing world.

The code sample below shows how to use the Renci.SshNet dll. It's free, here:

https://github.com/sshnet/SSH.NET

If I have occasion to need this again I'll blow it out into a full class, but for now I just need the upload.


 

Related Articles

... and you 'll find more on the NET Development Menu

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Try
 
        Dim host As String = "ftp.sample.com"
        Dim port As String = "22"
        Dim username As String = "myUseName"
        Dim password As String = "myPass"
        Dim f As New FileInfo("C:\temp\testfile.txt")
        Dim uploadfile As String = f.FullName
 
        Dim client = New SftpClient(host, port, username, password)
        client.Connect()
        If client.IsConnected Then
            Console.WriteLine("I AM CONNECTED")
        End If
        Dim ofileStream = New System.IO.FileStream(uploadfile, FileMode.Open)
 
        client.BufferSize = 4 * 1024
 
        Dim a As System.Action(Of ULong) = Nothing
        client.UploadFile(ofileStream, f.Name, a)
        client.Disconnect()
        client.Dispose()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
 
 
 
End Sub

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences