1. 程式人生 > >HTTP和FTP上傳檔案的比較

HTTP和FTP上傳檔案的比較

非常詳盡的HTTP和FTP檔案傳輸方式方面的比較。
Transfer Speed
Possibly the most common question: which is faster for transfers?
Given all details on this page. What makes FTP faster:
No added meta-data in the sent files, just the raw binary
Never chunked encoding "overhead"
What makes HTTP faster:
reusing existing persistent connections make better TCP performance
pipelining makes asking for multiple files from the same server faster
(automatic) compression makes less data get sent
no command/response flow minimizes extra round-trips
Ultimately the net outcome of course differ depending on specific details, but I would say that for single-shot static files, you won't be able to measure a difference. For a single shot small file, you might get it faster with FTP (unless the server is at a long round-trip distance). When getting multiple files, HTTP should be the faster one.
Age
FTP (RFC 959) appeared roughly ten years before HTTP was invented. FTP was the one and only protocol back then. The initial traces of what become RFC 959 can be found already as early as 1971 (RFC 114)
Upload
Both protocols offer uploads. FTP has an "append" command, where HTTP is more of a "here's data coming now you deal with it" approach.
It could be worth noticing that WebDAV is a protocol on top of HTTP that provides "filesystem-like" abilities
ASCII/binary/EBCDIC
FTP has a notion of file format so it can transfer data as ASCII or binary (and more) where HTTP always sends things binary. FTP thus also allows text conversions when files are sent between systems of different sorts:
If the destination uses a different scheme for encoding End-Of-Line characters ftp will correct it for the destination. For example unix uses only a NL (newLine x'0A') character and MS windows uses CR and LF (CarriageReturn and LineFeed x'0D0A'). MS windows includes a CTRL-Z (x'1A') as an end of file character, unix does not. EBCDIC specifies that a translation be performed from ASCII to EBCDIC (used on old mainframes).
HTTP provides meta-data with files, Content-Type, which clients use but FTP has no such thing. The meta data can thus be used by clients to interpret the contents accordingly.
Headers
Transfers with HTTP always also include a set of headers that send meta data. FTP does not send such headers. When sending small files, the headers can be a significant part of the amount of actual data transfered. HTTP headers contain info about things such as last modified date, character encoding, server name and version and more.
Pipelining
HTTP supports pipelining. It means that a client can ask for the next transfer already before the previous one has ended, which thus allows multiple documents to get sent without a round-trip delay between the documents, and TCP packets are thus optimized for transfer speed.
Something related, although not similar, is FTP's support for requesting multiple files to get transferred in parallel using the same control connection. That's of course using new TCP connections for each transfer so it'll get different performance metrics.
FTP Command/Response
FTP involves the client sending commands to which the server responds. A single transfer can involve quite a series of commands. This of course has a negative impact since there's a round-trip delay for each command. HTTP transfers are primarily just one request and one response (for each document). Retrieving a single FTP file can easily get up to 10 round-trips.
Two Connections
One of the biggest hurdles about FTP in real life is its use of two connections. It uses a first primary connection to send control commands on, and when it sends or receives data, it opens a second TCP stream for that purpose.
Firewalls and NATs
FTP's use of two connections, where the second one use dynamic port numbers and can go in either direction, gives the firewall admins grief and firewalls really have to "understand" FTP at the application protocol layer to work really well.
This also means that if both parties are behind NATs, you cannot use FTP!
Additionally, as NATs often are setup to kill idle connections and the nature of FTP makes the control channel remain quiet during long and slow FTP transfers, we often end up with the control channel getting cut off by the NAT due to idleness.
Active and Passive
FTP opens the second connection in an active or passive mode, which basically says which end that initiates it. It's a client decision to try either way.
Encrypted Control Connections
Since firewalls need to understand FTP to be able to open ports for the secondary connection etc, there's a huge problem with encrypted FTP (FTP-SSL or FTPS) since then the control connection is sent encrypted and the firewall(s) cannot interpret the commands that deal with creating the second connection. Also, the FTPS standard took a very long time to "hit it" so there exists a range of hybrid versions out in the wild.
Authentications
FTP and HTTP have a different set of authentication methods documented. While both protocols offer basically plain-text user and password by default, there are several commonly used authentication methods for HTTP that isn't sending the password as plain text, but there aren't as many (non-kerberos) options available for FTP.
Download
Both protocols offer support for download. Both protocols used to have problems with file sizes larger than 2GB but those are history for modern clients and servers on modern operating systems.
Ranges/resume
Both FTP and HTTP support resumed transfers in both directions, but HTTP supports more advanced byte ranges.
Resumed transfers for FTP that start beyond the 2GB position has been known to cause trouble in the past but should be better these days.
Persistent Connections
For HTTP communication, a client can maintain a single connection to a server and just keep using that for any amount of transfers. FTP must create a new one for each new data transfer. Repeatedly doing new connections are bad for performance due to having to do new handshakes/connections all the time and redoing the TCP slow start period and more.
HTTP Chunked Encoding
To avoid having to close down the data connection in order to signal the end of a transfer - when the size of the transfer wasn't known when the transfer started, chunked encoding was introduced in HTTP.
During a "chunked encoding" transfer, the sending party sends a stream of [size-of-data][data] blocks over the wire until there is no more data to send and then it sends a zero-size chunk to signal the end of it.
Another obvious benefit (apart from having to re-open the connection again for next transfer) with chunked encoding compared to plain closing of the connection is the ability to detect premature connection shutdowns.
Compression
HTTP provides a way for the client and server to negotiate and choose among sevel compression algorithms. The gzip algorithm being the perhaps most compact one.
FTP offers an official "built-in" run length encoding that compresses the amount of data to send, but not by a great deal on ordinary binary data. It has also traditionally been done for FTP using various "hackish" approaches that were never in any FTP spec.
FXP
FTP supports "third party transfers", often called "FXP". It allows a client to ask a server to send data to a third host, a host that isn't the same as the client. This is often disabled in modern FTP servers though due to the security implications.
IPv6
HTTP and FTP both support ipv6 fine, but the original FTP spec had no such support and still today many FTP servers don't have support for the necessary commands that would enable it. This also goes for the firewalls in between that need to understand FTP.
Name based virtual hosting
Using HTTP 1.1, you can easily host many sites on the same server and they are all differentiated by their names.
In FTP, you cannot do name based virtual hosting at all until the HOSTcommand gets implemented in the server you talk to and in the ftp client you use... It is a recent spec without many implementations.
Dir Listing
One area in which FTP stands out somewhat is that it is a protocol that is directly on file level. It means that FTP has for example commands for listing dir contents of the remote server, while HTTP has no such concept.
However, the FTP spec authors lived in a different age so the commands for listing directory contents (LIST and NLST) don't have a specified output format so it's a pain to write programs to parse the output. Latter specs (RFC3659) have addressed this with new commands like MLSD, but they are not widely implemented or supported by neither servers nor clients.
Proxy Support
One of the biggest selling points for HTTP over FTP is its support for proxies, already built-in into the protocol from day 1. The support is so successful and well used that lots of other protocols can be sent over HTTP these days just for its ability to go through proxies.
FTP has always been used over proxies as well, but that was never standardized and was always done in lots of different ad-hoc approaches.
Further
There are further differences, like the HTTP ability to do conditional requests, negotiate content language and much more but those are not big enough to be specified in this document.

相關推薦

HTTPFTP檔案比較

非常詳盡的HTTP和FTP檔案傳輸方式方面的比較。Transfer SpeedPossibly the most common question: which is faster for transfers?Given all details on this page. Wh

【Android基礎知識】使用HttpHttpClient檔案

public class UploadThread extends Thread{ private String fileName; private String url; public UploadThread(String fileName,String url){ this.fileName

Java ftp 檔案下載檔案

今天同事問我一個ftp 上傳檔案和下載檔案功能應該怎麼做,當時有點懵逼,畢竟我也是第一次,然後裝了個逼,在網上找了一段程式碼發給同事,叫他除錯一下。結果悲劇了,執行不通過。(裝逼失敗) 我找的文章連結:http://blog.csdn.net/yucaifu1989/art

第10步 (1)logback.xml日誌配置(2) ftp(檔案)伺服器配置(3) idea注入自動編譯配置(4)專案提交gitee(5)fe助手restlet client

****************************************************************************************************************************************** 1.直接複製&

android http通過post檔案提交引數(通過拼裝協議)

HttpURLConnection conn = null; DataOutputStream outStream = null;try{           String BOUNDARY = "---------------------------7da2137580

批處理實現增拷貝檔案增量檔案ftp伺服器

1、實現從原始檔夾篩選指定天數內修改文件,拷貝到目的資料夾。 2、將本地檔案上傳到指定的ftp伺服器。  @echo off   rem 拷貝檔案到中間資料夾  del /f /q /a D:\work\backup\data\*.*  rem @echo off

http使用post檔案時,請求頭主體資訊總結

HEADER:  寫道 ...... Content-Type: multipart/form-data; BODY: Content-type: multipart/form-data, boundary=AaB03x --AaB03x content-d

C#中PUTPOST檔案

HttpClient中上傳檔案 上一篇主要是提到了HttpClient幫助類,這次針對於上傳檔案進行補充,僅做記錄 public static string HttpUploadFile(string url, string path) {

ftp檔案到伺服器

<?php class Ftp { public $off; // 返回操作狀態(成功/失敗) public $conn_id; // FTP連線 const FTP_HOST=''; const FTP_PORT='21'; const FTP_USER=

java通過ftp 檔案到伺服器

package com.dl.utils; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ja

用java實現ftp檔案

實際專案需求:從資料庫查詢資訊,在本地生成檔案,再上傳到ftp 所用Jar包:NetComponents.jar 核心程式碼: import java.io.File; import java.io.FileInputStream; import java.io.IOExcepti

基於SSM框架實現利用FTP檔案至Linux遠端伺服器

基於SSM框架實現利用FTP上傳檔案至Linux遠端伺服器 摘要:JavaWEB開發通常採用SSM框架,在完成web開發時經常涉及到遠端訪問Linux伺服器實現檔案上傳。通常實現檔案上傳可通過InputStream和OutputStream實現檔案讀寫操作,但對於Linux伺服器需要

AJAXfrom-檔案示例【django專案】

專案簡述 本Django專案為測試例項專案,用於學習測試。 分別用三種Django檔案上傳方式(form方式、jQuery+jQuery.ajax方式、原生JS+原生ajax方式)做上傳功能示例 檔案檔案釋義 form_upload.htmlform上傳檔案靜態頁面 jquery_ajax_upl

java ftp檔案 支援併發

package com.dl.utils; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ja

java ftp檔案 但是不支援併發

package com.dl.utils; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ja

PHP使用FTP檔案到伺服器(實戰篇)

我們在做開發的過程中,上傳檔案肯定是避免不了的,平常我們的程式和上傳的檔案都在一個伺服器上,我們也可以使用第三方sdk上傳檔案,但是檔案在第三方伺服器上。現在我們使用PHP的ftp功能把檔案上傳到我們自己的伺服器,我使用的linux的伺服器,首先確保伺服器上配置好ftp,以vsftpd為例。 FTP類,此類包

java實現FTP(檔案)、下載(檔案、資料夾、資料夾遞迴)、刪除(檔案、資料夾遞迴)

提示:必須先保證有在FTP上上傳、下載、刪除的許可權! 本文結構 ---- 先給出測試樣例(圖片版),再給出工具類程式碼(文字版)! 上傳測試 注意:.uploadFile(String remoteDir, String remoteFileName, F

Java實現FTP檔案到Linux伺服器的那些坑

一、Linux安裝FTP服務         首先Linux伺服器需要安裝FTP服務,步驟如下: 1、執行如下ftp服務安裝命令: yum install vsftpd 可能會出現如下錯誤: "Couldn't open file /m

PHP利用FTP檔案

簡單示例:  $ftpfile = $_FILES['userfile'];//檔案資訊 $conn = ftp_connect('127.0.0.1', 21, 90);//替換為自己的IP ftp_login($conn, 'user', 'password');//替

Linux通過FTP檔案到伺服器

1.如果沒有安裝ftp,可執行: 輸入:yum -y install ftp,回車 等待安裝完畢 2.連線伺服器 輸入:ftp 伺服器IP,回車 根據提示輸入使用者名稱和密碼 3.上傳下載操作 1). 上傳 put 格式:put local-file [remote-file] 將本地檔案上