Skip to content

Instantly share code, notes, and snippets.

@nicholas0g
Created May 10, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholas0g/dbb4b20464ec947ecf10406ea237912d to your computer and use it in GitHub Desktop.
Save nicholas0g/dbb4b20464ec947ecf10406ea237912d to your computer and use it in GitHub Desktop.
SFTP upload in VB.NET
' Important: It is helpful to send the contents of the
' sftp.LastErrorText property when requesting support.
Dim sftp As New Chilkat.SFtp
' Any string automatically begins a fully-functional 30-day trial.
Dim success As Boolean = sftp.UnlockComponent("Anything for 30-day trial")
If (success <> True) Then
Console.WriteLine(sftp.LastErrorText)
Exit Sub
End If
' Set some timeouts, in milliseconds:
sftp.ConnectTimeoutMs = 15000
sftp.IdleTimeoutMs = 15000
' Connect to the SSH server.
' The standard SSH port = 22
' The hostname may be a hostname or IP address.
Dim port As Integer
Dim hostname As String
hostname = "www.my-ssh-server.com"
port = 22
success = sftp.Connect(hostname,port)
If (success <> True) Then
Console.WriteLine(sftp.LastErrorText)
Exit Sub
End If
' Authenticate with the SSH server. Chilkat SFTP supports
' both password-based authenication as well as public-key
' authentication. This example uses password authenication.
success = sftp.AuthenticatePw("myLogin","myPassword")
If (success <> True) Then
Console.WriteLine(sftp.LastErrorText)
Exit Sub
End If
' After authenticating, the SFTP subsystem must be initialized:
success = sftp.InitializeSftp()
If (success <> True) Then
Console.WriteLine(sftp.LastErrorText)
Exit Sub
End If
' Upload from the local file to the SSH server.
' Important -- the remote filepath is the 1st argument,
' the local filepath is the 2nd argument;
Dim remoteFilePath As String = "hamlet.xml"
Dim localFilePath As String = "c:/temp/hamlet.xml"
success = sftp.UploadFileByName(remoteFilePath,localFilePath)
If (success <> True) Then
Console.WriteLine(sftp.LastErrorText)
Exit Sub
End If
Console.WriteLine("Success.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment