HINT: download all files from remote folder - WeOnlyDo Discussion board

HINT: download all files from remote folder (General questions)

by wodSupport, Sunday, November 21, 2004, 18:57 (7305 days ago)

This is VB6 code (but can easily be applied to other languages) that will download all files from remote folder, in async mode. It will first get list of all files, and then download them one by one. You must change the code to set your Login, Password, Hostname, and also LocalDir and RemoteDir.

[code]Option Explicit
Dim WithEvents SFTP As wodSFTPCom
Dim RemoteDir As String
Dim LocalDir As String
Dim FileList As Collection

Private Sub Form_Load()
Set SFTP = New wodSFTPCom
SFTP.Login = **login**
SFTP.Password = **password**
SFTP.HostName = **hostname**

RemoteDir = /home2/kreso/udp/
LocalDir = c:\a\
Set FileList = New Collection

SFTP.Connect
End Sub

Private Sub SFTP_AttributesData(ByVal Items As wodSFTPCOMLib.ISftpItems)
Dim i As Integer
Dim item As SftpItem

For Each item In Items
If (item.Permissions And 16384) = 0 Then
FileList.Add item.Name
End If
Next
End Sub

Private Sub SFTP_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
If ErrorCode = 0 Then
SFTP.ListAttributes RemoteDir
Else
MsgBox ErrorText
End If
End Sub

Private Sub SFTP_Disconnected()
MsgBox Done!
End Sub

Private Sub SFTP_Done(ByVal ErrorCode As Integer, ByVal ErrorText As String)
Dim fname As String

If ErrorCode <> 0 Then
Debug.Print ERROR: & ErrorText
End If

If FileList.Count > 0 Then
fname = FileList.item(1)
FileList.Remove 1

Debug.Print Downloading & fname
SFTP.GetFile LocalDir, RemoteDir + fname
Else
SFTP.Disconnect
End If
End Sub
[/code]


Complete thread: