Dev Direct Solution Center

For more information and to buy this product...

Use wodSFTP to upload or download multiple files with wildcard matching

  For a copy of the sample project please click here to download and install the product evaluation.

Introduction

The Secure File Transfer Protocol (SFTP client) provides secure file transfer functionality over any reliable data stream, SSH in this case. It is the standard file transfer protocol for use with the SSH2 protocol. This windowless wodSFTP component implements the client side of this protocol which is reliable and easy to use. SFTP is not just an "FTP over SSH" wrapper - it is a newer protocol, supported by all SSH2 servers as their subsystem.

Detail

Our demonstration code illustrates how to upload/download several files to and from a server, and filter some of them out during the transfer.

Instructions

Download and run the executable from the above link. The samples will be placed in directory C:\Program Files\WeOnlyDo.Com\SFTP\Samples. There are example projects for VB, ASP, Delphi, VC and VBS.

In the VB6 project, the control wodSFTP is placed on Form1 and event handlers are provided by the development environment.

This example code will try to download every txt file from a remote folder including subdirectories.

In Form_Load we provide wodSFTP with a remote hostname and our login and password...

VB6
Private Sub Form_Load() wodSFTP1.HostName = "ENTER.YOUR.HOST" wodSFTP1.Login = "ENTER.YOUR.LOGIN" wodSFTP1.Password = "ENTER.YOUR.PASSWORD" ...

...and then we use Connect to establish a connection.

VB6
... wodSFTP1.Connect End Sub

The Connect will issue a call to the Connected event with information if the connection is successfully established. If true, we simply use GetFiles to retrieve remote files.

VB6
Private Sub wodSFTP1_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String) If ErrorText <> "" Then 'error occured MsgBox ErrorText Else ' no error Sftp1.GetFiles App.Path, "/usr/share/doc", 0 End If End Sub

As seen in above code snippet, GetFiles takes three parameters. First is a local path the files will be downloaded to, second one is a remote path and the third one tells wodSFT how deep into subdirectories it should recursively go.

After GetFiles is issued, wodSftp will call the LoopItem event for every remote file found in the specified remote path. In this event handler we decide whether we want a certain file to be downloaded or not by checking RemoteFile and setting the Skip parameter to a proper value.

VB6
Private Sub wodSFTP1_LoopItem(LocalFile As String, RemoteFile As String, ByVal ItemType As DirItemTypes, Skip As Boolean) If Right$(RemoteFile, 4) = ".txt" Then ' default value of Skip is false Else ' skip all except subdirectories since they have to be browsed too If ItemType <> typeDirectory Then Skip = True End If End If End Sub

When all files have been looped, the Done event will be called and that is where we close the connection.

VB6
Private Sub wodSFTP1_Done(ByVal ErrorCode As Integer, ByVal ErrorText As String) wodSFTP1.Disconnect End Sub

Now our App.Path should contain all *.txt files found in "/usr/share/doc/" on a remote server. Remember, to use the same technique when uploading multiple files - you simply use PutFiles instead of GetFiles and then above code will also work perfectly.

Summary

In this example we showed how simple it is to upload/download multiple files with wodSFTP and how easy it is to filter them using the LoopItem event.

Visit WeOnlyDo! Inc. for more information and more samples.