Hi
i need some advice because i have some problems with idftp dirs upload !
the current code working but the problem that upload start from subdirectories
only !
Example :
+MainDir
-SubDir1
-SubDir2
-.........
Upload will transfer (SubDir1 & SubDir2,..) but will not creat (MainDir) folder
transfer will be directly for subdirectories !
Код:
procedure UploadFTP;
procedure GetDir(dir: string);
var
SearchRec: TSearchRec;
details, nodetails: TStringList;
k: Integer;
begin
if FindFirst(dir + '*.*', faAnyFile, SearchRec) = 0 then
begin
repeat
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
//if we found a folder
if (SearchRec.Attr and faDirectory) = faDirectory then
begin
//get folder contents from ftp. one with details, one without
details := TStringList.Create;
nodetails := TStringList.Create;
Form1.idFTP1.List(details, '', True);
Form1.idFTP1.List(nodetails, '', False);
for k := details.Count - 1 downto 0 do
begin
if details.Strings[k] <> '' then
begin
if (details.Strings[k][1] <> 'd') or
(nodetails.Strings[k] = '.') or
(nodetails.Strings[k] = '..') then
begin
details.Delete(k);
nodetails.Delete(k);
end;
end;
end;
if nodetails.IndexOf(SearchRec.Name) = -1 then
begin
Form1.idFTP1.MakeDir(SearchRec.Name);
end;
Form1.idFTP1.ChangeDir(SearchRec.Name);
details.Free;
nodetails.Free;
GetDir(dir + SearchRec.Name + '\');
Form1.idFTP1.ChangeDirUp;
end
else
begin
Form1.idFTP1.Put(dir + SearchRec.Name, SearchRec.Name);
end;
end;
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
var
dir: string;
details, nodetails: TStringList;
k: Integer;
begin
with Form1.idFTP1 do
begin
Host := Form1.FtpServerEdit.Text;
Username := 'root';
// Adjust your data here
Password := Form1.PasswordEdit.Text;
Passive := True;
end;
//if you want to upload you data to an remote-directory, enter it below (does not matter if 'dir\dir' or 'dir/dir')
dir := StringReplace('', '\', '/', [rfReplaceAll]);
if dir <> '' then
begin
if dir[1] = '/' then Delete(dir, 1, 1);
if dir[Length(dir)] <> '/' then dir := dir + '/';
while Pos('/', dir) > 0 do
begin
details := TStringList.Create;
nodetails := TStringList.Create;
Form1.idFTP1.List(details, '', True);
Form1.idFTP1.List(nodetails, '', False);
for k := details.Count - 1 downto 0 do
begin
if details.Strings[k] <> '' then
begin
if (details.Strings[k][1] <> 'd') or
(nodetails.Strings[k] = '.') or
(nodetails.Strings[k] = '..') then
begin
details.Delete(k);
nodetails.Delete(k);
end;
end;
end;
if nodetails.IndexOf(Copy(dir, 1, Pos('/', dir) - 1)) = -1 then
begin
Form1.idFTP1.MakeDir(Copy(dir, 1, Pos('/', dir) - 1));
end;
Form1.idFTP1.ChangeDir(Copy(dir, 1, Pos('/', dir) - 1));
Delete(dir, 1, Pos('/', dir));
details.Free;
nodetails.Free;
end;
end;
dir := Form1.spSkinSelectDirectoryDialog1.Directory;
if dir[Length(dir)] <> '\' then dir := dir + '\';
GetDir(dir);
Form1.idFTP1.Disconnect;
end;
regards , yassinov