Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

idftp uploading in delphi

Posted on 2011-03-17
3
Medium Priority
?
1,459 Views
Last Modified: 2012-06-21
Hello experts.Please help me with one trouble.
i have 2 function :
function CopySubDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        form3.idftp1.MakeDir(FTPTargetDir+sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'\');
     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

function CopyDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \ and /
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        if (FTPTargetDir='') then
          form3.idftp1.ChangeDir('/')
        else form3.idftp1.ChangeDir(FTPTargetDir);
        form3.idftp1.MakeDir(sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'/');

     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

This working good.This function makes dirs to ftp server from pc folder.
Please help : how i can modify this function that it uploads ALL files from any dir?

Thanks.
0
Comment
Question by:helyonprime96
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 1000 total points
ID: 35160723
change that function first so you aren't dependant on form3 anymore
 
function CopyDirStruct(Dir, FTPTargetDir: string; IdFtp: TIdFtp): integer;  // Dir & FTPTargetDir Should be teminated with \ and /
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        if (FTPTargetDir='') then
          idftp.ChangeDir('/')
        else 
          idftp.ChangeDir(FTPTargetDir);
        idftp.MakeDir(sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'/');

     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

Open in new window


how do you call this func ?
0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 1000 total points
ID: 35162595
Try this please:
Procedure UploadFiles(Dir, FTPTargetDir: string);
var
  SR : TSearchRec;
begin
  // Dir is the Path of the directory you are searching its files
  if FindFirst(Dir + '*.*', faAnyFile, SR) = 0 then
    begin
      repeat
        if (SR.Attr <> faDirectory) then
          begin
            // the file path can be obtained by using Dir+SR.Name so you can upload it or do whatever you want with it
            form3.idftp1.Put(Dir + SR.Name, FTPTargetDir + SR.Name);
          end;
       until FindNext(SR) <> 0;
      FindClose(SR);
    end;
end;

function CopySubDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        form3.idftp1.MakeDir(FTPTargetDir+sr.Name);
        UploadFiles(Dir + SR.Name+'\', FTPTargetDir+SR.Name+'\');
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'\');
     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

function CopyDirStruct(Dir, FTPTargetDir: string): integer;  // Dir & FTPTargetDir Should be teminated with \ and /
var
  sr: TSearchRec;
  n: integer;
begin
  n:= 0;
  if FindFirst(Dir+'*.*', faDirectory, sr) = 0 then
  begin
    repeat
      if ((sr.Attr and faDirectory)=sr.Attr) and (Pos('.', sr.Name)=0) then
     begin
        if (FTPTargetDir='') then
          form3.idftp1.ChangeDir('/')
        else form3.idftp1.ChangeDir(FTPTargetDir);
        form3.idftp1.MakeDir(sr.Name);
        n:= n + CopySubDirStruct(Dir+sr.Name+'\', FTPTargetDir+sr.Name+'/');

     end;
    until FindNext(sr) <> 0;
    FindClose(sr);
  end;
  Result:= n;
end;

Open in new window

Consider what Geert said.
0
 

Author Closing Comment

by:helyonprime96
ID: 35168630
thanks experts.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question