Shortcut Menu

Skip

Main Navigation

Choose your language


ActiveXperts Network Component Add network capabilities to any Windows or .NET application

Quicklinks


Network Component - SFtp Object

SFTP (Secure File Transfer Protocol) allows secure network file transfer over an insecure network, such as the Internet.

The Secure File Transfer Protocol is an extension to the SSH version 2.0 protocol. Most SSH server implementations will also allow for SFTP logins. SFTP is the secure successor to FTP.

The Network Component SFTP implementation is based on the PuTTY implementation. With the Network Component SFtp object, you can login onto a remote machine running the SSH-2 daemon and has the SFTP service enabled.

There are two ways to authenticate: by using a password or by using a 'private key'. When using a password to authenticate it is required that the host private key is known to the system. If the hosts private key is unknown to the system or if it was changed since the last connection the Ssh object will return an error. To connect anyway and store the host key in the registry for future connections the 'AcceptHostKey' property can be set.

The Ssh object is part of the Network Component. Overview of all Network Component objects:

DnsServer & DnsRecord - Ftp & FtpFile - Http - Icmp - IPtoCountry - Msn - Ntp - Radius - Rsh - Scp - SFtp - Ssh - SnmpManager - SnmpTrapManager - SnmpMibBrowser - Tcp - Tftp - TraceRoute - Udp - Xen - Wake-on-LAN - Xen (Citrix)


SFtp Sample code

VBScrip sample: Change directory and get a file

' Helper function to expand a string variable to a specified length
Function Pad(ByRef Text, ByVal Length)
  Pad = Left(Text & Space(Length), Length)
End Function

' Helper function to test and find the error description and exit
Function test_lasterror()
  If objSFtp.LastError <> 0 Then
    WScript.Echo "Error "  & objSFtp.LastError
    If objSFtp.ProtocolError <> "" Then 
      WScript.Echo "Protocol error: " & objSFtp.ProtocolError
      WScript.Quit 1
    End If     
  End If
End Function

' Connect to the host
Set objSFtp      = CreateObject("ActiveXperts.SFtp") ' Create an SFtp instance
objSFtp.Host     = "192.168.1.10"          ' Hostname or IP address of remote LINUX machine
objSFtp.UserName = "demo"                  ' Login as 'demo'
objSFtp.Password = "topsecret"             ' Use a password to login

WScript.Echo "Connect"
objSFtp.Connect                            ' Connect to the SFTP server
test_lasterror

' Change directory
objSFtp.ChangeDir "test"
test_lasterror

' List directory contents
Set f = objSFtp.FindFirstFile(".")
test_lasterror
While objSFtp.LastError = 0
  str = pad(f.name, 30) & pad(f.SizeKb & "KB", 10) & f.Date
  WScript.Echo str
  Set f = objSFtp.FindNextFile    
WEnd

' Get smalltoken file
objSFtp.GetFile "Smalltoken.file", "."
test_lasterror

objSFtp.Disconnect

' YES, command has completed
WScript.Echo "Ready."

On ftp.activexperts-labs.com, you can find a lot of Network Component samples. These samples are also part of the Network Component installation.

Visit ftp.activexperts-labs.com