给你一个例子, 使用FTP控件下载一个目录
delphi中的nmftp控件中Download函数只能下载一个文件,没有提供一个下载整个目录(包含子目录)的函数。
我编写了个实现目录下载功能的方法,需要用到该功能的用户可参考一下。
file://目录下载
function tftp.ex_download(remote_dir,local_dir:string):boolean;
var
i,j,count1:integer;
att,ss:string;
current_dir:string;
temp_dir:string;
begin
try begin
NMFTP1.ChangeDir(remote_dir);
current_dir:=remote_dir;
temp_dir:=copy(current_dir,2,length(current_dir));
if not DirectoryExists(local_dir) then CreateDir(local_dir);
if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir);
nmftp1.ParseList:=true;
NMftp1.list;
count1:=nmftp1.FTPDirectoryList.name.Count;
for i:=0 to count1-1 do begin
file://必须
NMFTP1.ChangeDir(current_dir);
nmftp1.list;
ss:=nmftp1.FTPDirectoryList.name.Strings[i];
att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];
if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then begin
if not DirectoryExists(local_dir) then CreateDir(local_dir);
NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);
end
else begin
if not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss);
file://递归调用
ex_download(remote_dir+ss+'\',local_dir);
end;
end;
result:=true;
end
except
On E:Exception do begin
result:=false;
end;
end;
end;
delphi中的nmftp控件中Download函数只能下载一个文件,没有提供一个下载整个目录(包含子目录)的函数。
我编写了个实现目录下载功能的方法,需要用到该功能的用户可参考一下。
file://目录下载
function tftp.ex_download(remote_dir,local_dir:string):boolean;
var
i,j,count1:integer;
att,ss:string;
current_dir:string;
temp_dir:string;
begin
try begin
NMFTP1.ChangeDir(remote_dir);
current_dir:=remote_dir;
temp_dir:=copy(current_dir,2,length(current_dir));
if not DirectoryExists(local_dir) then CreateDir(local_dir);
if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir);
nmftp1.ParseList:=true;
NMftp1.list;
count1:=nmftp1.FTPDirectoryList.name.Count;
for i:=0 to count1-1 do begin
file://必须
NMFTP1.ChangeDir(current_dir);
nmftp1.list;
ss:=nmftp1.FTPDirectoryList.name.Strings[i];
att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];
if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then begin
if not DirectoryExists(local_dir) then CreateDir(local_dir);
NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);
end
else begin
if not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss);
file://递归调用
ex_download(remote_dir+ss+'\',local_dir);
end;
end;
result:=true;
end
except
On E:Exception do begin
result:=false;
end;
end;
end;
解决方案 »
- StringGrid中一个Cell的字符串,能设成多个颜色吗?
- 问下delphi程序做好后,想打包成安装包,能同时安装数据库,不知道那位有什么好的办法都教我一下
- 我见大家都说一个月挣多少多少K,K是多少钱啊?不会是块吧?3块?4块?
- 大学生找工作怎么那么难???
- access ,如果提高循环插入的效率问题,请帮忙。。。
- delphi加access的安装问题,再线等待
- 如何使DbGrid的某一个单元格为不可编辑?
- 急!!!!个人版的sql2000上开发的delphi数据库软件能在sql server 2000服务器上的通用吗?前两个每人20分!!!
- 请问如何将应用程序的图标放到Windows的状态栏里头(跟音量控制一样)
- Delphi6新增功能大家谈
- qq中察看聊天纪录的窗口中右边那个表格,有没有类似的控件
- 全屏动态显示多幅图片,如何解决图形切换时的闪烁问题?
begin
NMFTP1.List;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
TheDir: String;
begin
if InputQuery('Change Directory', 'Which directory?', TheDir) then
NMFTP1.ChangeDir(TheDir);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
TheDir: String;
begin
if InputQuery('Create Directory', 'Directory name?', TheDir) then
NMFTP1.MakeDirectory(TheDir);
end;
procedure TForm1.Button5Click(Sender: TObject);
var
TheDir: String;
begin
if InputQuery('Remove Directory', 'Directory name?', TheDir) then NMFTP1.RemoveDir(TheDir);
end;
procedure TForm1.Button6Click(Sender: TObject);
var
TheFile: String;
begin
if InputQuery('Delete File', 'File name?', TheFile) then
NMFTP1.Delete(TheFile);
end;
procedure TForm1.Button7Click(Sender: TObject);
var
OldFile,
NewFile: String;
begin
if InputQuery('Rename file', 'File to rename?', OldFile) then
if InputQuery('Rename file', 'New file name?', NewFile) then
NMFTP1.Rename(OldFile, NewFile);
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
ShowMessage('After reinitilizing, you must click the authenticate button');
NMFTP1.Reinitialize;
end;
procedure TForm1.Button9Click(Sender: TObject);
var AnID,
APass: String;
begin
if InputQuery('Authentication needed', 'Enter User ID', AnID) then
if InputQuery('Authentication needed', 'Enter Password', APass) then
begin
NMFTP1.DoCommand('USER '+AnID);
NMFTP1.DoCommand('PASS '+APass);
end;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
ShowMessage(NMFTP1.CurrentDir);
end;
procedure TForm1.NMFTP1AuthenticationFailed(var Handled: Boolean);
var
ThePass,
TheID: String;
begin
if MessageDlg('Authentication Failed. Retry?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
ThePass := NMFTP1.Password;
TheID := NMFTP1.UserID;
InputQuery('Reauthenticate', 'Enter User ID', TheID);
InputQuery('Reauthenticate', 'Enter Password', ThePass);
NMFTP1.Password := ThePass;
NMFTP1.UserID := TheID; Handled := TRUE;
end;
end;
procedure TForm1.NMFTP1AuthenticationNeeded(var Handled: Boolean);
var
APass,
AnID: String;
begin
if NMFTP1.Password = '' then
begin
if InputQuery('Password needed', 'Enter password: ', APass) then
begin
NMFTP1.Password := APass;
Handled := TRUE;
end
else
Handled := FALSE;
end; if NMFTP1.UserID = '' then
begin
if InputQuery('User ID needed', 'Enter User ID: ', AnID) then
begin
NMFTP1.UserID := AnID;
Handled := TRUE;
end
else
Handled := FALSE;
end;
end;