先connect ftp server;
使用命令user/pass验证用户
发送命令TYPE A设置ASC 传送模式
命令PASV使用被动连接,接收server返回的ip:port
发送LIST命令,连接刚才得到的ip:port接受文件列表
对你得到的每个文件进行{
sendcmd:PASV
recvdata:ip port
sendcmd:RETR 文件名
connect ip port
读取文件数据
}换目录用CWD [dir]命令
更详细的资料请参考FTP协议(中文版)
http://www.longen.com/E-K/detaile~k/FTP.htm

解决方案 »

  1.   

    另外,所有的数据连接都是在你检查到socket关闭的时候结束。
      

  2.   

    人民邮电出版社<visual c++网络高级编程>里面有一章介绍ftp协义的实现
      

  3.   

    头文件:Wininet.h
    函数说明:
    General Win32 Internet FunctionsThe general Microsoft&reg; Win32&reg; Internet functions described in this section perform basic Internet file manipulations.InternetAttemptConnect Attempts to make a connection to the Internet. 
    InternetCheckConnection Allows an application to check if a connection to the Internet can be established. 
    InternetCloseHandle Closes a single Internet handle. 
    InternetConfirmZoneCrossing Checks for changes between secure and nonsecure URLs. When a change occurs in security between two URLs, an application should allow the user to acknowledge this change, typically by displaying a dialog box. 
    InternetConnect Opens an FTP, Gopher, or HTTP session for a given site. 
    InternetErrorDlg Displays a dialog box for the error that is passed to InternetErrorDlg, if an appropriate dialog box exists. If the FLAGS_ERROR_UI_FILTER_FOR_ERRORS flag is used, the function also checks the headers for any hidden errors and displays a dialog box if needed. 
    InternetFindNextFile Continues a file search started as a result of a previous call to FtpFindFirstFile or GopherFindFirstFile. 
    InternetGetLastResponseInfo Retrieves the last Win32&reg; Internet function error description or server response on the thread calling this function. 
    InternetInitializeAutoProxyDll Not currently supported. 
    InternetLockRequestFile Allows the user to place a lock on the file that is being used. 
    InternetOpen Initializes an application's use of the Win32&reg; Internet functions. 
    InternetQueryDataAvailable Queries the server to determine the amount of data available. 
    InternetQueryOption Queries an Internet option on the specified handle. 
    InternetReadFile Reads data from a handle opened by the InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest function. 
    InternetReadFileEx Reads data from a handle opened by the InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest function. 
    InternetSetFilePointer Sets a file position for InternetReadFile. This is a synchronous call; however, subsequent calls to InternetReadFile might block or return pending if the data is not available from the cache and the server does not support random access. 
    InternetSetOption Sets an Internet option. 
    InternetSetOptionEx Not currently implemented. 
    InternetSetStatusCallback Sets up a callback function that Win32&reg; Internet functions can call as progress is made during an operation. 
    InternetTimeFromSystemTime Formats a date and time according to the HTTP version 1.0 specification. 
    InternetTimeToSystemTime Takes an HTTP time/date string and converts it to a SYSTEMTIME structure. 
    InternetUnlockRequestFile Unlocks a file that was locked using InternetLockRequestFile. 
    InternetWriteFile Writes data to an open Internet file. 
    用InternetConnect建立连接
    用FtpFindFirstFile查找文件
    用FtpGetFile FtpPutFile上传或下载
    用FtpSetCurrentDirectory切换路径!
      

  4.   

    Kevin_qing():
    发送PASV后,是不是用recv接受服务器发送过来的IP和PORT?那么服务器发送过来的IP和PORT的格式是什么样的啊?
    同样,发送LIST命令后接收到的文件列表是一个长字符串吗?他们用什么分割开各个文件?Bardo(巴顿):
    你说的只是用在WINDOWS上的,我要的是纯C的,可以在LINUX和UNIX下编译使用的。
      

  5.   

    pasv的返回里面ip:port格式是这样的
    210,34,4,5,7,174
    等于
    210.34.4.5:(7<<8)+174;
    LIST命令各种FTP实现不太一样,格式可能不会一致,处理比较麻烦。
    你可以使用NLST命令,这样得道的是以<CRLF>("\r\n")分割的字符串。
      

  6.   

    谢谢Kevin_qing() ,给分。
    另外,Kevin_qing() 请到以下去领分。http://www.csdn.net/expert/topic/545/545089.xml