FTP 协议和 HTTP 协议的12点比较(文件上传/下载)

fmms 9年前
     <div id="OSChina_News_28162" class="NewsContent TextContent NewsType2">     <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    许多站点,比如<span style="font-family:'Times New Roman';">非死book</span><span style="font-family:宋体;">或一些博客等都允许用户上传或下载文件,比如论坛或博客系统的图片。在这种情况下,通常有两种选择上传文件到服务器,那就是</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">协议和</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">协议。</span></span></p>     <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>     <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;">    </span></span><span style="font-family:宋体;font-size:10.5pt;">以下列出了一些两者的不同点:</span></p>     <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:宋体;font-size:10.5pt;"><br /> </span></p>     <div class="Section0">      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"> </p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">1、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP<span style="font-family:宋体;">协议是用来浏览网站的,而</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">是用来访问和传输文件的,</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">文件传输有点批量上传和维护网站的意思,而</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">文件传输更多的是为终端用户提供文件传输,比如电影、图片、音乐之类。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p> </p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">2、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP <span style="font-family:宋体;">和 </span><span style="font-family:'Times New Roman';">FTP </span><span style="font-family:宋体;">客户端:通常的</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">客户端就是浏览器,而</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">服务可以通过命令行或者用户自有的图形界面客户端。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">3、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP <span style="font-family:宋体;">头:</span><span style="font-family:'Times New Roman';">HTTP </span><span style="font-family:宋体;">头包含了 </span><span style="font-family:'Times New Roman';">metadata </span><span style="font-family:宋体;">,比如说最后更改的日期、编码方式、服务器名称版本还有其他的一些信息,而这些在</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">中是不存在的。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">4、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">FTP<span style="font-family:宋体;">要比</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">早出现</span><span style="font-family:'Times New Roman';">10</span><span style="font-family:宋体;">年左右。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">5、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">数据格式:<span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">能传输</span><span style="font-family:'Times New Roman';">ACSII</span><span style="font-family:宋体;">数据或者二进制格式的数据,而</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">只用二进制格式。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">6、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP<span style="font-family:宋体;">中的流水线:</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">支持流水线,这就意味着客户端可以在上一个请求处理完之前,发出下一个请求,其结果就是多次请求数据之前省掉了部分服务器客户端往返时延。而</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">并没有这项支持。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">7、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP<span style="font-family:宋体;">中的动态端口:</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">一个最大的问题就是它使用两个连接,第一个连接用来发送控制指令,当接受或者发送数据的时候,又打开第二个</span><span style="font-family:'Times New Roman';">TCP</span><span style="font-family:宋体;">连接。而</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">在双向传输中使用动态端口。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">8、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP<span style="font-family:宋体;">中的持久连接:对一个</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">会话来讲,客户端可以维护一个单个的连接并使用它进行任意数量的数据传输。</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">每次有数据的需要时都创建一个新的连接。重复的创建新的连接带来的体验并不好,因为每次创建连接都必须让双方握手验证,这消耗了很多时间。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">9、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP<span style="font-family:宋体;">中的压缩算法:</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">提供了一个在一些压缩算法中客户端和服务器共同协商选择的办法。其中</span><span style="font-family:'Times New Roman';">gzip</span><span style="font-family:宋体;">可以说是最有影响力的一种,而</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">中并不存在这种复杂的算法。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">10、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">HTTP<span style="font-family:宋体;">支持代理:</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">一个很大的特点就是支持代理,这种功能是构建在协议里的,而</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">并不支持。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">11、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">而<span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">也能脱颖而出的一点是这个协议是直接面向文件级别的。这以为着</span><span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">有例如可以通过命令列出远程服务器上的目录列表,而</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">没有这个概念。</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">12、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">速度:可能最通常的问题了:哪一个传输更快?</span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    什么使<span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">服务更快?</span></span></p>      <p style="margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    1、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">没有在发出的数据中加入<span style="font-family:'Times New Roman';">meta-data</span><span style="font-family:宋体;">,仅传输原二进制文件。</span></span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    2<span style="font-family:宋体;">、没有过度的分块编码</span></span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    什么使<span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">服务更快?</span></span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    1、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">重用已存在的持久连接,从而有更好的<span style="font-family:'Times New Roman';">TCP</span><span style="font-family:宋体;">表现。</span></span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    2、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">流水线的支持使得从同一个服务器上请求多个文件更快。</span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    3、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">自动的压缩机制使得传输的数据更少。</span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">    4、</span><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">没有命令<span style="font-family:'Times New Roman';">/</span><span style="font-family:宋体;">应答机制最大限度的减少了往返时延。</span></span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"> </p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';">总结:当然最终的结果会因具体的情况而异,但我想说的是,单次传输一个静态的文件,很难衡量两者的区别对单个的小文件来说,<span style="font-family:'Times New Roman';">FTP</span><span style="font-family:宋体;">传输更快,当传输多个文件时,</span><span style="font-family:'Times New Roman';">HTTP</span><span style="font-family:宋体;">更快。</span></span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><br /> </span></span></p>      <p style="text-align:justify;margin-top:0pt;margin-bottom:0pt;" class="p0"><span style="font-family:'宋体';font-size:10.5pt;mso-spacerun:'yes';"><span style="font-family:宋体;"><a href="/misc/goto?guid=4958337616067085894" target="_blank">原文链接</a>,</span></span><span style="text-align:left;padding-bottom:0px;line-height:22px;background-color:#f9f9f9;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:微软雅黑, Verdana, sans-serif, 宋体;color:#4466bb;font-size:14px;padding-top:0px;">OSChina.NET</span><span style="text-align:left;line-height:22px;background-color:#f9f9f9;font-family:微软雅黑, Verdana, sans-serif, 宋体;font-size:14px;"> 编译</span></p>     </div>    </div>