943,099 Members | Top Members by Rank

Ad:
Jul 10th, 2007
0

FTP get (with wildcards) in Delphi?

Expand Post »
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.
Similar Threads
Reputation Points: 483
Solved Threads: 1
Posting Shark
EnderX is offline Offline
999 posts
since Aug 2006
Jul 17th, 2007
0

Re: FTP get (with wildcards) in Delphi?

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?
Reputation Points: 14
Solved Threads: 16
Junior Poster
radu84 is offline Offline
171 posts
since Dec 2006
Sep 7th, 2007
0

Re: FTP get (with wildcards) in Delphi?

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]
Pascal and Delphi Syntax (Toggle Plain Text)
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. var
  3. AFiles : TStringList;
  4. stroll : integer;
  5. parse : integer;
  6. chop : integer;
  7. trucount : integer;
  8. edifile : string;
  9. stamped : string;
  10. stampfile : string;
  11.  
  12. begin
  13.  
  14. {perform the inbound inquery}
  15. with idftp2 do begin
  16. sql_memo.Clear;
  17. Afiles := TStringList.Create;
  18. disconnect;
  19. connect(true);
  20. changedir('/elvis/sandwich/company');
  21. List(AFiles,'945.*',true);
  22. sql_memo.Lines.Addstrings(listresult);
  23. Disconnect;
  24. end;
  25.  
  26. trucount:= 0;
  27.  
  28. with sql_memo do begin
  29. for stroll:=0 to lines.Count-1 do begin
  30. if pos('945.',lines[stroll]) > 0 then begin
  31. trucount:=trucount+1;
  32. end;
  33. end;
  34. end;
  35.  
  36. if trucount > 0 then begin
  37.  
  38. {secure and trim the filenames}
  39. with sql_memo do begin
  40. for stroll:=0 to lines.Count-1 do begin
  41. if pos('945.',lines[stroll]) > 0 then begin
  42. parse:=pos('945.',lines[stroll]);
  43. chop:=length(lines[stroll]);
  44. lines[stroll]:=copy(lines[stroll],parse,chop-parse+1);
  45. end;
  46. end;
  47. end;
  48.  
  49. {ftp 'get' the filenames}
  50. with sql_memo do begin
  51. idftp2.connect(true);
  52. idftp2.changedir('/elvis/sandwich/company');
  53. for stroll:=0 to lines.count-1 do begin
  54. edifile:=lines[stroll];
  55. idftp2.Get(edifile,'c:\home\'+edifile);
  56. idftp2.Delete(edifile);
  57. end;
  58. idftp2.disconnect;
  59. end;
  60.  
  61.  
  62. {attempt to mirror the the standardized filename 945in.YYMMDDhhnn}
  63. {stamped:=formatdatetime('yymmddhhnnsszzz',now); }
  64.  
  65. {ftp 'put' to archive the filenames}
  66. with sql_memo do begin
  67. idftp2.connect(true);
  68. idftp2.changedir('/elvis/sandwich/archive/company');
  69. for stroll:=0 to lines.count-1 do begin
  70. stamped:=formatdatetime('yymmddhhnnsszzz',now);
  71. edifile:=lines[stroll];
  72. stampfile:='945in.'+stamped;
  73. idftp2.put('c:\home\'+edifile,stampfile,false);
  74. end;
  75. idftp2.disconnect;
  76. end;
  77.  
  78. {now reverse this but append the files into 945xxx.txt}
  79. with sql_memo do begin
  80. idftp1.connect(true);
  81. idftp1.changedir('/company/ediin');
  82. for stroll:=0 to lines.count-1 do begin
  83. edifile:=lines[stroll];
  84. idftp1.put('c:\home\'+edifile,'945xxx.txt',true);
  85. end;
  86. edifile:='945xxx.txt';
  87. idftp1.Get(edifile,'c:\home\'+edifile);
  88. idftp1.disconnect;
  89. end;
  90.  
  91. end; {end of trucount condition}
  92. end;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tsbrownstone is offline Offline
4 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: I need help on audio encoding and accessing freeDB.
Next Thread in Pascal and Delphi Forum Timeline: Debug an Exe from other Exe which loads it in Delphi7





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC