FTP get (with wildcards) in Delphi?

Reply

Join Date: Aug 2006
Posts: 999
Reputation: EnderX is an unknown quantity at this point 
Solved Threads: 1
EnderX EnderX is offline Offline
Posting Shark

FTP get (with wildcards) in Delphi?

 
0
  #1
Jul 10th, 2007
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.
"No trees were harmed in the production of this post. However, several electrons were severely inconvenienced."

Kumquat.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 171
Reputation: radu84 is an unknown quantity at this point 
Solved Threads: 16
radu84 radu84 is offline Offline
Junior Poster

Re: FTP get (with wildcards) in Delphi?

 
0
  #2
Jul 17th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 2
Reputation: tsbrownstone is an unknown quantity at this point 
Solved Threads: 0
tsbrownstone's Avatar
tsbrownstone tsbrownstone is offline Offline
Newbie Poster

Re: FTP get (with wildcards) in Delphi?

 
0
  #3
Sep 7th, 2007
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;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum


Views: 4848 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC