用WinINet Api 开发FTP客户端 (一)

FTP Sessions
FTP 会话


The Win32 Internet functions can be used to provide applications with the ability to navigate and manipulate directories and files on an FTP server. Applications that use a CERN proxy exclusively must use the InternetOpenUrl function because CERN proxies do not support FTP. For more information on how to use InternetOpenUrl, see Accessing URLs directly.
Win32 Internet 函数能够给应用程序提供浏览和操作FTP服务器上文件和目录的能力。


To begin an FTP session, use InternetConnect to create the valid FTP session handle to be used by the FTP functions provided with the Win32 Internet functions.
为了开始一个FTP会话,需要用Win32 Internet 函数的InternetConnect命令来创建一个有效的FTP会话句柄。


The Win32 Internet functions provide the capability to navigate between directories; enumerate, create, remove, and rename directories; and rename, upload, download, and delete files on an FTP server.
这些Win32 Internet 函数能够提供对FTP服务器上的目录的操作例如:在目录间导航、列举目录、建立目录、删除目录、目录改名;以及对文件的操作例如:更改文件名、更新、下载和删除文件等。


Navigation is provided by the FtpGetCurrentDirectory and FtpSetCurrentDirectory functions. These functions utilize the FTP session handle created by a previous call to InternetConnect to determine which directory the application is currently in or to change to a different subdirectory.
目录间导航用到了FtpGetCurrentDirectory和FtpSetCurrentDirectory这两个函数。这些函数利用InternetConnect函数创建的FTP会话句柄来检测应用程序所处的当前目录,或者改变当前目录到一个其他子目录。


Directory enumeration is performed by using the FtpFindFirstFile and InternetFindNextFile functions. FtpFindFirstFile uses the FTP session handle created by InternetConnect to find the first file that matches the given search criteria and returns a handle to continue the directory enumeration. InternetFindNextFile uses the handle returned by FtpFindFirstFile to return the next file that matches the original search criteria. The application should continue to call InternetFindNextFile until there are no more files left in the directory.
通过执行FtpFindFirstFile和InternetFindNextFile函数可以得到目录的列表。FtpFindFirstFile同样使用InternetConnect创建的FTP会话句柄,来找到第一个符合条件的文件,同时返回一个用来继续枚举目录的句柄。InternetFindNextFile使用这个句柄返回下一个符合条件的文件。程序可以继续使用InternetFindNextFile直至在当前目录下没有符合条件的文件。


New directories are created by using the FtpCreateDirectory function. This function uses the FTP session handle created by InternetConnect and creates the directory specified by the string passed to the function. The string can contain a directory name relative to the current directory, or a fully qualified directory path.
可以使用FtpCreateDirectory函数建立新的目录。这个函数要使用到InternetConnect创建的FTP会话句柄和一个指定的字符串来创建目录。这个字符串可以是一个相对路径的目录名,也可以是包含完整的路径。


To rename either files or directories, the application can call FtpRenameFile. This function replaces the original name with the new name passed to the function. The name of the file or directory can be relative to the current directory, or a fully qualified name.
要对文件或目录改名,可以使用FtpRenameFile函数。这个函数使用新的名字替换原有的名字。这个新的文件或目录名可以使用相对路径或者使用完整路径。


To upload or place files on an FTP server, the application can use either FtpPutFile or FtpOpenFile (along with InternetWriteFile). FtpPutFile can be used if the file already exists locally, while FtpOpenFile and InternetWriteFile can be used if data needs to be written to a file on the FTP server.
如果需要在线更新FTP服务器上的文件,可以使用FtpPutFile或者FtpOpenFile(要配合InternetWriteFile)。FtpPutFile用于本地存有该文件时,而FtpOpenFile和InternetWriteFile用在需要在线更新文件时。


To download or get files, the application can use either FtpGetFile or FtpOpenFile (with InternetReadFile). FtpGetFile is used to retrieve a file from an FTP server and store it locally, while FtpOpenFile and InternetReadFile can be used to control where the downloaded information is going (for example, it could be used to display the information in an edit box).
下载文件可以使用FtpGetFile或者FtpOpenFile(配合InternetReadFile)。FtpGetFile被用于从Ftp服务器上下载文件到本地,而FtpOpenFile和InternetReadFile能够用于在下载期间进行控制。例如:它能够在一个编辑框显示一些下载方面的信息。


Deleting files on an FTP server is done by using the FtpDeleteFile function. This function removes a file name that is either relative to the current directory or a fully qualified file name from the FTP server. FtpDeleteFile requires an FTP session handle returned by InternetConnect.
删除文件要用到FtpDeleteFile函数。这个函数会将当前目录下的文件或者包含完整路径的文件从服务器上删除。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值