I'm supposed to be writing a program to pick up files left in an ftp server directory. I have ftp access to the directory, and I have a copy of the Indy pack components installed on my system. However, I'm running into a problem.

The files I'm supposed to be picking up don't have static names. That is, each file is in the format XX-YY-ZZ.csv, where XX and ZZ are constant, but YY is variable. I don't mean simply that it can change, I mean that it's determined on the other side by something I can't predict...in this case, the YY portion of the filename is the timestamp at which the file was created, as far as I can understand the spec sheet I'm working off of.

As I said, I can't predict the value of the timestamp portion of the filenames. As a result, I'm having trouble trying to figure out how to get the files downloaded. As far as I can tell, the Indy component TIdFTP's 'get' functionality won't allow wildcards, and I can't think of any other way to get the files I'm supposed to retrieve.

I have several questions regarding this:

1 .Does anyone know whether or not the TIdFTP component has functionality for the mget command? I know it's possible to give the mget a wildcarded target, but I haven't seen anything in the method list for the component that looks like mget. Am I just looking under the wrong name?

2. If the TIdFTP component can't handle an mget or a wildcarded get statement, could someone recommend another FTP component that can handle one of these options?

3. If there are no reasonable ways to get this done in Delphi, would someone please recommend another programming language it might be easier to do this in?

Thank you for your consideration.

hi,

try also the components from JEDI project, you find them on google and are free. also have you took a look at indy's examples?

i found a workaround using idftp capabilities
i needed a way to ftp numerous files for edi.
the filenames aren't standardized, so i came up
with this approach...

basically, i dump the listresult in a memo component
and use the line text in the memo to perform a pseudo mget

in my situation i needed to get several files from one server,
archive them to a different directory on that server, and append all the
files to a single file for a different server.

idftp2 is the host server
idftp1 is the receiving server

hope this helps ...

[code=language]
procedure TForm1.Button3Click(Sender: TObject);
var
AFiles : TStringList;
stroll : integer;
parse  : integer;
chop   : integer;
trucount : integer;
edifile : string;
stamped : string;
stampfile : string;

begin

{perform the inbound inquery}
with idftp2 do begin
sql_memo.Clear;
Afiles := TStringList.Create;
disconnect;
connect(true);
changedir('/elvis/sandwich/company');
List(AFiles,'945.*',true);
sql_memo.Lines.Addstrings(listresult);
Disconnect;
end;

trucount:= 0;

with sql_memo do begin
for stroll:=0 to lines.Count-1 do begin
if pos('945.',lines[stroll]) > 0 then begin
trucount:=trucount+1;
end;
end;
end;

if trucount > 0 then begin

{secure and trim the filenames}
with sql_memo do begin
for stroll:=0 to lines.Count-1 do begin
if pos('945.',lines[stroll]) > 0 then begin
parse:=pos('945.',lines[stroll]);
chop:=length(lines[stroll]);
lines[stroll]:=copy(lines[stroll],parse,chop-parse+1);
end;
end;
end;

{ftp 'get' the filenames}
with sql_memo do begin
idftp2.connect(true);
idftp2.changedir('/elvis/sandwich/company');
for stroll:=0 to lines.count-1 do begin
edifile:=lines[stroll];
idftp2.Get(edifile,'c:\home\'+edifile);
idftp2.Delete(edifile);
end;
idftp2.disconnect;
end;


{attempt to mirror the the standardized filename 945in.YYMMDDhhnn}
{stamped:=formatdatetime('yymmddhhnnsszzz',now); }

{ftp 'put' to archive the filenames}
with sql_memo do begin
idftp2.connect(true);
idftp2.changedir('/elvis/sandwich/archive/company');
for stroll:=0 to lines.count-1 do begin
stamped:=formatdatetime('yymmddhhnnsszzz',now);
edifile:=lines[stroll];
stampfile:='945in.'+stamped;
idftp2.put('c:\home\'+edifile,stampfile,false);
end;
idftp2.disconnect;
end;

{now reverse this but append the files into 945xxx.txt}
with sql_memo do begin
idftp1.connect(true);
idftp1.changedir('/company/ediin');
for stroll:=0 to lines.count-1 do begin
edifile:=lines[stroll];
idftp1.put('c:\home\'+edifile,'945xxx.txt',true);
end;
edifile:='945xxx.txt';
idftp1.Get(edifile,'c:\home\'+edifile);
idftp1.disconnect;
end;

end; {end of trucount condition}
end;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.