EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Wildcard characters in SFTP file names

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#547
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

XXX~XXX~20060626.csv.gz.

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;
SFTP_PublicKey.LoadPublicKey(keyLocation);
FKeyStorage := TElSSHMemoryKeyStorage.Create(nil);
FKeyStorage.Add(SFTP_PublicKey);
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;
ElSimpleSFTPClient1.Open();
if ElSimpleSFTPClient1.Active then
begin
ElSimpleSFTPClient1.DownloadFile(remoteDirectory + remoteFileName, localDirectory + localFileName);
end;
ElSimpleSFTPClient1.Close();
--------------------------------------------------
#548
Posted: 06/28/2006 01:51:19
by Eugene Mayevski (EldoS Corp.)

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


Sincerely yours
Eugene Mayevski
#1330
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
begin
directoryHandle := ElSimpleSFTPClient1.OpenDirectory(remoteDirectory);
directoryListing := TList.Create;
ElSimpleSFTPClient1.ReadDirectory(directoryHandle,directoryListing);

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

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

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


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 3321 times

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




|

Back to top

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

Got it!