EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Wildcard characters in SFTP file names

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
Posted: 06/27/2006 16:42:41
by Dan Hammari (Basic support level)
Joined: 06/27/2006
Posts: 11

I am creating an application that will download a file from a secure FTP site using public key authentication. The name of the file I am downloading contains a date, but the rest of the file name is extremely variable. For example, the file could be called


How do I go about using wildcards to select the one file I need to download each day?

Here is code I have cobbled together so far:
SFTP_Site := frmSettings.txtSFTP_Site.Text;
SFTP_UserName := frmSettings.txtUserName.Text;
SFTP_PublicKey := TElSSHKey.Create;
keyLocation := frmSettings.txtPublicKey.Text;
FKeyStorage := TElSSHMemoryKeyStorage.Create(nil);
SFTP_Port := 22;
remoteDirectory := frmSettings.txtRemoteLocation.Text;
remoteFileName := '*' + TodaysDate + '.csv.gz';
localDirectory := frmSettings.txtLocalLocation.Text;
localFileName := remoteFileName;

ElSimpleSFTPClient1.Address := SFTP_Site;
ElSimpleSFTPClient1.Username := SFTP_UserName;
ElSimpleSFTPClient1.KeyStorage := FKeyStorage;
ElSimpleSFTPClient1.Port := SFTP_Port;
ElSimpleSFTPClient1.AuthenticationTypes := SSH_AUTH_TYPE_PUBLICKEY;
ElSimpleSFTPClient1.EncryptionAlgorithms[SSH_EA_3DES] := False;
ElSimpleSFTPClient1.EncryptionAlgorithms[SSH_EA_DES] := False;
if ElSimpleSFTPClient1.Active then
ElSimpleSFTPClient1.DownloadFile(remoteDirectory + remoteFileName, localDirectory + localFileName);
Posted: 06/28/2006 01:51:19
by Eugene Mayevski (Team)

You should read directory contents (using ReadDirectory method), and then download one or more files.

Sincerely yours
Eugene Mayevski
Posted: 10/02/2006 19:19:43
by Dan Hammari (Basic support level)
Joined: 06/27/2006
Posts: 11

Here is the code that I was able to make work:

if ElSimpleSFTPClient1.Active then
directoryHandle := ElSimpleSFTPClient1.OpenDirectory(remoteDirectory);
directoryListing := TList.Create;

for currentIndex := 0 to (directoryListing.Count - 1) do
directoryItem := directoryListing[currentIndex];
currentFileName := directoryItem.Name;
if AnsiContainsText(currentFileName, '20060626.csv.gz' then
remoteFileName := currentFileName;

if remoteFileName <> '' then
ElSimpleSFTPClient1.DownloadFile(remoteDirectory + remoteFileName, localDirectory + remoteFileName);
Posted: 10/03/2006 00:51:17
by Eugene Mayevski (Team)

So what the problem is? Run your code under debuger and see what's going on.

Sincerely yours
Eugene Mayevski



Topic viewed 3589 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!