delphiidftp控件用法(Delphiidftp控件用法)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
delphi idftp控件用法(Delphi idftp控件用法)
Delphi idftp control usage 2011-04-25 22:22FTP is a standard protocol that is the easiest way to exchange files between a computer and a network.
FTP is also an application protocol standard for applying TCP/IP protocol.
FTP usually in the file upload to the server, a commonly used way or from the server file transfer as a user, you can use FTP with a very simple DOS interface, can also be provided by the use of third party software (such as FLASHFXP) to the data server to delete, rename and other operations.
Of course, before using these, you have to log on to the server and log in with the specified username and password or Anonymous.
You know, but let's just talk about it. Using DOS to operate FTP, I'm not talking. Today I'm using IDFTP controls in INDY components to make a FTP client software (very simple)
I'm going to talk about some of the properties of the IDFTP control:
Host:FTP server address.
USER: user account number.
Password: password.
Passive: method for controlling FTP data connection. FTP data transmission can be active and passive.
PORT is active mode, when the data channel is established, the server to connect to others;
PASV is passive mode. When the data channel is set up, the server is connected to others;
When establishing data channel, PORT mode or PASV mode, the right of choice lies in the FTP client.
The passive in IDFTP is a Boolean data type. When True is active; when false is passive.
The default port for Port:FTP service is 21.
The type of TransferType: transport file can be valued as FtBinary (8 bit arbitrary file) and FtAscii (7 bit text file).
Description of SystemDesc:FTP server.
Several methods of IDFTP
The commonly used methods are as follows:
Connect: connects to the FTP server
Abort: stops the operation of FTP services.
Quit: closes the connection between the client and the server
Noop: is used to maintain connection commands and prevent connections from being turned off by the server
List: gets the list of files and directories on the FTP server
Prototype for
Procedure List (ADest:TStrings; Const ASpecifier:String; const ADetails:Boolean);
RetrieveCurrentDir: gets the name of the current directory
Site: sends commands to the FTP server
Prototype for:
Procedure Site (const ACommand:string);
ChangeDir: changes the current directory on the FTP server
The prototype is: procedure ChangeDir (const ADirName:string);
ChangeDirUp: returns the directory on the FTP server to your directory
Wenzhou -Dillon (86695893) 13:08:26
MakeDir: creates a new directory on the server
Prototype for:
Procedure MakeDir (const ADirName:String);
RemoveDir: deletes a directory on the server
Prototype for:
Procedure RemoveDir (const ADirName:string);
Get: downloads files from the FTP server. This method is overloaded
Prototype for:
Procedure Get (const ASourceFile:string; ADest:TStream); overload;
Procedure Get (const ASourceFile:string; const ADest:string; ACanOverWrite:Boolean); overload;
Put: is used to upload files to the server. This method is overloaded
Prototype for:
Procedure Put (const ASourceFile:TStream; const ADest:string; const Appand:Boolean); overload;
Procedure Put (const ASourceFile:string; const ADest:string; const AAppand:Boolean); overload;
KillDataChannal: closes the FTP data channel
The so-called "overloading" means that when some methods are inherited from multiple classes, conflicts can occur. In order to avoid this conflict, the overloaded function is used
Delete: deletes a file on the FTP server
原形为:程序删除(const afilename:字符串);
重命名:更改服务器上的文件名。
原型为:
程序重命名(const asourcefile:字符串;const adestfile:字符串);
尺寸:获取文件大小信息。
原型为:
功能尺寸(const afilename:字符串):整数;
当大家装好indy9.0附带一个例程,在印\ ftpdemo下可以找到。
是一个不错的演示
我仿造这个做的一个例子里面包含详细的注释演示。
当然,还要讲一下,做FTP客户端的心得哦
我现在,慢慢把里面的代码发了来做一下讲解
首先是登录按钮里的代码:
还是先给大家看一下这个界面吧
删除:删除FTP服务器上一个文件。
原形为:程序删除(const afilename:字符串);
重命名:更改服务器上的文件名。
原型为:
程序重命名(const asourcefile:字符串;const adestfile:字符串);
尺寸:获取文件大小信息。
原型为:
功能尺寸(const afilename:字符串):整数;
开始
ftpcon。
启用:= false;
/ / -----------------连接FTP服务器------------------ / /
与idftp做
开始
尝试
主持人:=装饰(置。
文本);/ / FTP服务器IP地址
用户名:=装饰(按2。
文本);/ /用户名
密码:=装饰(edit3。
文本);/ /密码
连接;/ /连接
directorylistbox.items.clear;/ /清空目录以及文件信息debuglistbox.items.clear;/ /清空记录信息
/ / SaveFTPHostInfo(饰(curdir。
文本),“ftphost”);最后
如果连接
开始
displaydir(TRIM(curdir。
文本));//改变当前路径FTPCon。
启用:= false;//连接按钮
FTPDisCon。
启用:= true;/ /断开按钮
结束;
结束;
结束;
结束;
断开按钮的代码:
开始
尝试
如果idftp。
连接/判断客户端是否连着服务器
IdFTP。
中止;
如果transferrigndata然后/判断客户端与服务器之间是否有数据传输
IdFTP。
退出;
最后
IdFTP。
断开;/ /断开连接
FTPCon。
启用:=真;
FTPDisCon。
启用:= false;
结束;
结束;
transferrigndata变量全局变量里有定义的
连接按钮里的displaydir的过程如下:
程序tfftpclient。
DisplayDir(目录名:字符串);
VaR
LS:tstringlist;
开始
LS:= tstringlist。
创建;
尝试
IdFTP . ChangeDir(目录);
IdFTP。
transfertype:= ftascii;/ /编译不通过时使用idftpcommon curdir。
正文:= idftp.retrievecurrentdir;
directorylistbox.items.clear;
IdFTP。
列表(LS);/ /把idftp里的列表与LS关联起来
目录列表框。
项目。
分配(LS);/ /把目录列表框与LS关联起来
如果directorylistbox.items.count > 0
如果AnsiPos(综合,目录列表框。
项目[ 0 ])> 0然后directorylistbox.items。
删除(0);
最后
ls,免费;
结束;
结束;
还有一个最重要的一段代码,就是ListBox如何显示目录信息的
首先,把ListBox的风格的属性改成lbownerdrawfixed
再在OnDrawItem方法里添加如下代码:
程序tfftpclient。
DirectoryListBoxDrawItem(控制:有有;
指数:整数;矩形:道;状态:townerdrawstate);
VaR
R:TRect;
开始
/ / ---------------------------------当选择一条记录时
如果odselected状态然后
开始
directorylistbox.canvas.brush.color:= $ 00895f0a;
directorylistbox.canvas.font.color:= clwhite;
结束
其他的
开始
directorylistbox.canvas.brush.color:= clwindow;
结束;
/ / ---------------------------------显示当前目录里的信息
如果指定的(idftp。
directorylisting)和(idftp。
directorylisting。
计数>指数)然后
开始
目录列表框。
画布用(矩形);
与idftp。
directorylisting项目[索引]做。
------------------------ / / / /
目录列表框。
帆布。
TextOut(rect.left,矩形,顶部,文件名);/ /文件名
R:=矩形;
·左:=矩形。
左+ headercontrol1。
部分。
项目[ 0 ]。
宽度;
------------------------ / / / /
R = R右:左+ headercontrol1。
部分。
项目[ 1 ]。
宽度;
目录列表框,用帆布(R);
目录列表框。
帆布。
TextOut(r.left,矩形,顶部,IntToStr(大小));//文件大小
------------------------ / / / /
左:右;
R = R右:左+ headercontrol1。
部分。
项目[ 2 ]。
宽度;
目录列表框,用帆布(R);
如果类型= ditdirectory然后/是文件夹类型编译不通过时要使用idftplist
目录列表框。
帆布。
TextOut(r.left,矩形,顶部,“文件夹”);
结束
其他的
开始
目录列表框。
帆布。
TextOut(r.left,矩形,顶部,“文件”);
结束;
------------------------ / / / /
左:右;
R = R右:左+ headercontrol1。
部分。
项目[ 3 ]。
宽度;
目录列表框,用帆布(R);
目录列表框。
帆布。
TextOut(r.left,矩形,顶部,formatdatetime ('yyyy-mm-dd HH:毫米,ModifiedDate));//修改时间
------------------------ / / / /
左:右;
R = R右:左+ headercontrol1。
部分。
项目[ 4 ]。
宽度;
目录列表框,用帆布(R);
目录列表框。
帆布。
TextOut(r.left,矩形,顶部,
Groupname); / / 组名
/ / ------------------------ / /
R. left: = R. right;
R. right: = R. left + headercontrol1.sections.items [5].Width;
Directorylistbox.canvas.fillrect (R);
Directorylistbox.canvas.textout (r.left, rect, top, ownername); / / 拥有者名字
/ / ------------------------ / /
R. left: = R. right;
R. right: = R. left + headercontrol1.sections.items [6].Width;
Directorylistbox.canvas.fillrect (R);
Directorylistbox.canvas.textout (r.left, rect, top, ownerpermissions + grouppermissions + userpermissions); / / 权限
End;
End;
End;
这几部分是这软件里的中心
不过, 可以通过idftp里的work, status, workbegin, workend来实现进度条
还有上传代码:
If idftp connected then.
Begin
If opendialog1 run then.
Try
Idftp.transfertype: = ftbinary;
Idftp.put (opendialog1.filename, extractfilename (opendialog1.filename));
Finally
Displaydir (idftp.retrievecurrentdir);
End;
End;
End;
这段代码, 首先要判断idftp是否还连着
下传代码如下:
温州 - Dillon (86695893) 13: 36: 23
Procedure tfftpclient.directorylistboxdblclick (sender: tobject);
Var.
Fname: string;
Begin
If not idftp connected then / / 判断ftp是否还连着服务器.
Exit;
Fname: = idftp.directorylisting.items
[directorylistbox.itemindex].Filename;
If idftp.directorylisting.items
[directorylistbox.itemindex].Itemtype = ditdirectory then / / 假如双击是文件夹, 就改变路径
Begin
Curdir. Text: = trim (fname);
Displaydir (curdir.text);
End
Else
Begin
Try
Savedialog1.filename: = name; / / 得到保存的文件名
If savedialog1 run then.
Begin
Idftp.transfertype: = ftbinary; / / 以二进制进行传输
Bytestotransfer: = idftp.size (name); / / 得到文件的大小
If FileExists (name) then
Begin
Case messagedlg (文件已经存在, 是否重新下载? ' , mtconfirmation, mbyesnocancel, 0) of
Mryes:
Bytestotransfer: = bytestotransfer - filesizebyname (name); / / filesizebyname在idglobal
Idftp.get (name, savedialog1.filename, false, true);
End;
Mrno:
Begin
Idftp.get (name, savedialog1.filename, true);
End;
Mrcancel:
开始
出口;
结束;
结束;
结束
其他的
IdFTP,(姓名、savedialog1.filename,假);
结束;
结束;
最后
结束;
结束;
结束;
我要直接做在目录列表框的双击方法里的,假如双击文件就下载,文件夹就打开
其它的功能,都是通过idftp的方法直接实现的。
例如新建目录:
VaR
目录:字符串;
开始
目录:= InputBox(“输入新目录名称','提示信息',');
如果目录名>”然后
IdFTP . MakeDir(目录);
displaydir(curdir。
文本);
最后
结束;
结束;
所以,对于FTP客户端的讲解也就如些了。
是啊,把所有代码都压缩传到共享里
空只是客户端连到服务器,不被服务端T了。