How to connect to a SFTP server (like freeSSHd) us - WeOnlyDo Discussion board

How to connect to a SFTP server (like freeSSHd) us (General questions)

by Duncan Newman, Tuesday, November 20, 2007, 11:55 (6213 days ago)

Never really answered anywhere ... and after a while of trying to figure it out I've got the following code. Hopefully it'll make it onto google at some point as there is nothing on SFTP via VBS to be found!

Feel free to use the code, or maybe add something similar to the documentation WOD :)

[code]
' This example connects to a password-less SFTP server
' authenticating using keys generated by Putty or similar.
' The user should be set ON THE SFTP server to Password: Disabled
' and Public Key authentication: Required
' =================================================================
' Set Variables
Option Explicit
Dim objFTP, lst, key
Set objFTP = WScript.CreateObject( WeOnlyDo.wodSFTPCom.1 , wod_ )
Set Key = WScript.CreateObject( WeOnlyDo.Keys.1 )
' =================================================================
' User configurable variables
' =================================================================

' Load the Private Key ready for use
key.Load c:privatekey.ppk
' If you have a password set on your key (you should really) use the following line instead:
' key.Load c:privatekey.ppk , password_on_key

' Set the hostname/IP to connect to
objFTP.Hostname = server.ip
' User name for the SFTP server
objFTP.Login = username
' Set authentication type to Public Key only
objFTP.Authentication = 2
' Set the Key ready for authentication
objFTP.PrivateKey = key
' =================================================================
' END OF User configurable variables
' =================================================================

objFTP.Blocking = 1
' Connect to server with settings....
objFTP.Connect


' Bit of random code to get something out (shows it is working)
' List directory....
objFTP.ListDir ( / )
lst = objFTP.ListItem
' Echo the results...
WScript.echo lst
' Disconnect...
objFTP.Disconnect

' Triggered events - this automatically fires upon connect....
Sub wod_Connected(ErrorCode, ErrorText)
WScript.Echo Connected & ErrorText
End Sub

' Triggered events - this automatically fires upon disconnect....
Sub wod_Disconnected()
WScript.Echo Disconnected
End Sub
[/code]


Complete thread: