CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

熟悉FTP协议的请进,总分400分相送。

楼主kkk16()2002-02-28 17:36:39 在 VC/MFC / 基础类 提问

谁能给我解决问题我这个和另一贴子http://www.csdn.net/expert/topic/545/545089.xml的总共400分相送。  
   
  我需要做一个C(不用MFC)的FTP客户端的程序。  
  比如我要下载ftp.abc.com上的目录mydir下的所有文件,用户名是aaa,密码是bbb。  
   
  我知道socket编程,但不知FTP协议。现在主要有以下疑问:  
  0.要做到以上功能,我该做的大致步骤是什么?  
  1.先用SOCKET连接到服务器21端口建立控制连接后,怎么再建立数据连接?  
  2.怎么样知道mydir目录下的文件个数和名称?  
  3.要实现以上功能,大概要发送一些什么命令?  
  4.我数据连接的socket怎么知道文件数据以传送完成了?  
   
  请高手给我详细讲讲实现以上功能的具体步骤和需要发送的命令,以及哪一步该做什么。  
  比如什么时候发什么命令,什么时候怎么样建立数据连接等等。  
  万分感谢! 问题点数:200、回复次数:11Top

1 楼Kevin_qing()回复于 2002-02-28 17:57:39 得分 160

先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  
   
   
   
  Top

2 楼Kevin_qing()回复于 2002-02-28 17:58:49 得分 0

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

3 楼cayw(天行者)回复于 2002-02-28 18:30:25 得分 0

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

4 楼cayw(天行者)回复于 2002-02-28 18:30:48 得分 0

不知对你有没有帮助  
  Top

5 楼Bardo(巴顿(永远只有一个))回复于 2002-02-28 19:24:04 得分 40

头文件:Wininet.h  
  函数说明:  
  General   Win32   Internet   Functions  
   
  The   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切换路径!Top

6 楼Bardo(巴顿(永远只有一个))回复于 2002-02-28 19:24:52 得分 0

这样仅是一个Win32程序!Top

7 楼kkk16()回复于 2002-03-01 08:53:51 得分 0

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

8 楼kkk16()回复于 2002-03-01 09:02:16 得分 0

最好能有部分代码。Top

9 楼shenleav(午枫)回复于 2002-03-01 09:35:03 得分 0

关注Top

10 楼Kevin_qing()回复于 2002-03-01 09:56:27 得分 0

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

11 楼kkk16()回复于 2002-03-04 14:46:57 得分 0

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

相关问题

  • 熟悉http协议的大虾请进!
  • 熟悉mime协议的请进来。
  • 熟悉MIME协议的请进来!
  • 熟悉Telnet协议的请进
  • 谁有ftp,smtp,pop3,icmp ,igmp的协议文档
  • 关于FTP协议的问题
  • 谁有ftp协议的详细说明
  • 了解ftp协议的朋友请进
  • 熟悉网络协议的高手们,给点提示!
  • 熟悉手机编程的请进:关于FBUS协议

关键词

  • .net
  • win32
  • 文件
  • ip
  • 连接
  • 协议
  • 数据
  • 服务器
  • internet
  • socket

得分解答快速导航

  • 帖主:kkk16
  • Kevin_qing
  • Bardo

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo