GetFile or GetFiles with * - WeOnlyDo Discussion board

GetFile or GetFiles with * (wodSFTP / wodSFTP.NET / wodSFTPdll)

by rcuadra, Saturday, March 14, 2009, 16:05 (5516 days ago)

I want to use GetFile(s) for copy one file from a linux diretory to my Windows computer.

The problem is that in linux diretory exist more that 50,000 files, and the other problem is that I don´t know the exact name of the file, just know tha the file finist with some unique ID.

Example:

SFTP.GetFile C:DirectoryMynewnamefile , /LinuxDirectory/*UniqueID

How can I do for copy the file, because just wori if I write the comple name of the file in my linux server.

Thanks for you help,

Rodrigo

Re: GetFile or GetFiles with *

by woddrazen, Saturday, March 14, 2009, 19:47 (5515 days ago) @ rcuadra

Hi Rodrigo,


You can try using GetFiles Method and LoopItem Event.

GetFiles Method will trigger LoopItem Event before each file will be downloaded. You can then in LopItem Event skip files you don't want to download and download only files you need with Unique ID.

More help for LoopItem Event you can find here:
http://www.weonlydo.com/SFTP/Help/wodSFTPLib~wodSFTP~LoopItem_EV.html

You can find in help file example how to skip items.

Let us know how it goes.


Regards,
Drazen

Re: GetFile or GetFiles with *

by rcuadra, Sunday, March 15, 2009, 00:35 (5515 days ago) @ woddrazen

Drazen:

The problem of LooItem is tha is too slow when I have 100,000 files.

Whe need to loop all file for locate the file that I need to download.

What happen if I need to download just one file in the directory that have 100,000 files?

Thanks,


Rodrigo Cuadra

Re: GetFile or GetFiles with *

by woddrazen, Sunday, March 15, 2009, 18:09 (5514 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