delphi - 使用 Delphi XE 从 FTP 服务器下载目录
问题描述
我使用了这个代码,但我有时会收到““xxx.xxx”不理解的错误信息。而且它没有下载,而且我收到“无法建立数据连接:连接超时”消息。
我的 ConnectionTimeOut 设置是 240000。
我能做些什么?你能帮我吗?我正在使用德尔福 XE。
有美好的一天。
解决方案
最好包含您自己的代码来解决您的问题。但是,要下载我的文件,我将文件或文件夹压缩到服务器上,然后在客户端收到以下代码:
var
STListZip: TStringList;
SZipDown: String;
fFtp:TIdFTP;
begin
fFtp := TIdFTP.Create(nil);
fFtp.Passive := true;
fFtp.Host := 'myserver.com';
fFtp.Username := 'u1';
fFtp.Password := '1';
fFtp.port:='21';
fFtp.ConnectTimeout := 20000;
fFtp.TransferTimeout := 20000;
try
fFtp.Connect;
fFtp.ChangeDir('');
except
on E: Exception do
begin
ShowMessage('ERROR ftp not connect');
Exit;
end;
end;
if fFtp.Connected then
begin
STListZip := TStringList.Create;
fFtp.List(STListZip, 'abc.zip', false);
if STListZip.Count < 1 then
begin
ShowMessage('ERROR file not exist');
Exit;
end;
STListZip.Sort;
SZipDown := STListZip[STListZip.Count - 1];
try
fftp.BeginWork(wmRead);
fftp.Get(SZipDown, 'd:\', true, fftp.ResumeSupported);
fftp.Disconnect();
fftp.EndWork(wmRead);
except
on E: Exception do
begin
ShowMessage('ERROR File not download');
Exit;
end;
end;
end;
end;
abc.zip
注意:您可以代替*.zip
获取所有 zip 文件名。
推荐阅读
- authentication - 将自定义身份验证 jar 添加到 kafka
- yii2 - 如何避免CKeditor在调用时加载文件
- appsody - docker run -i --rm -p 8080:8080 默认值:appsody quarkus 堆栈的最新失败
- python - 线性模型文本分类中的特征重要性,StandardScaler(with_mean=False) yes or no
- python - Pandas 数据框中一列的多个聚合以返回两列
- c++ - 即使在离开作用域之后,如何访问在 C++ 中分配在堆上的变量?
- angular - 错误地添加了服务人员。删除了它,但如何从现有的计算机上取下它?
- laravel - 在模型中需要时使用虚拟类进行测试
- css - Nginx pod 不提供 css 文件
- java - 在 NASA Worldwind 中实现 XYZ 平铺层