Re: GetFile or GetFiles with * - WeOnlyDo Discussion board

Re: GetFile or GetFiles with * (General questions)

by woddrazen, Sunday, March 15, 2009, 18:09 (5733 days ago) @ rcuadra

Hi Rodrigo,


Sorry for slower reply it's weekend here.

I understand your problem. Unfortunately there is no custom list command in SFTP protocol that will list only certain files. You are searching for some unique word inside filename and until all files is listed you cannot be sure that all such files is downloaded.

However to workaround this problem. You can connect to that server using SSH2 protocol, send command that will list only files with certain unique word in filename (that will take MUCH less time) and download such files.

To do that you should combine our two components. wodSFTP ActiveX component for downloading files and wodSSH ActiveX component for collecting files.

wodSSH will connect to your server and send command that will list files only with unique word inside filename. Then you can store such files in collection, connect with wodSFTP to server and download that files using GetFile Method.

Here is code snippet.

[code]Dim ssh1 As wodSSHCom
Set ssh1 = New wodSSHCom

ssh1.HostName = hostname
ssh1.Login = login
ssh1.Password = password
ssh1.Protocol = SSH2
ssh1.Blocking = True
ssh1.Timeout = 30
ssh1.Connect

Dim output As String
Dim collFile As Collection
Set collFile = New Collection

ssh1.WaitFor ( regex:[$ #>] $ )
ssh1.DataReady = 0
output = ssh1.Execute( cd drazen + vbLf, regex:[$ #>] $ ) 'go in sub directory if needed
ssh1.DataReady = 0
output = ssh1.Execute( find . -maxdepth 1 -name '*txt' -printf ' f\n' + vbLf, regex:[$ #>] $ ) 'execute command that will search for files that have txt inside filename
ssh1.Disconnect
'---------------------------------------------------------
Dim pos As Integer
Dim entry() As String

entry = Split(output, vbCrLf, , vbTextCompare)
pos = 0

Do While pos < UBound(entry)
If Trim$(entry(pos)) <> Then
If InStr(1, entry(pos), txt ) > 0 Then
collFile.Add entry(pos) 'put files in collection
End If
End If
pos = pos + 1
Loop
'---------------------------------------------------------
Dim sftp1 As wodSFTPCom
Set sftp1 = New wodSFTPCom

sftp1.HostName = hostname
sftp1.Login = login
sftp1.Password = password
sftp1.Blocking = True
sftp1.Timeout = 30
sftp1.Connect

Dim i As Integer

For i = 1 To collFile.Count
sftp1.GetFile c:\something\ & collFile.Item(i), /home/something/ & collFile.Item(i) 'download files
Next i

sftp1.Disconnect[/code]
Here is link if you need more help for Unix find command:
http://content.hccfl.edu/pollock/Unix/FindCmd.htm

Let us know how it goes.


Regards,
Drazen


Complete thread: