FTP 簡介

  1. File Transfer Protocol (FTP) 是一種 client server 架構的檔案傳輸協定,使用者可以不用登入 server 下,傳輸檔案。
  2. FTP 使用多個 ports, FTP 開始連接時使用 server port 21,連上後要傳送資料使用的 ports,要看使用的模式及設定。
  3. FTP 模式:Passive and Active modes
  4. Active mode
    1. FTP client 開啟一個隨機選擇的 TCP port 呼叫 FTP server 的 port 21 請求連線。順利完成 Three-Way Handshake 後,連線成功建立。
    2. client 告訴 server,client 可以用另一個 TCP port 做數據通道。
    3. server 用 port 20 和剛才 client 所告知的 TCP port (大於 1024) 建立數據連線。傳送包含 SYC flag 的數據包給 client。
    4. client 返回一個帶 ACK flag 的確認封包﹐完成另一次的 Three-Way Handshake 手續。
    5. 開始數據傳送。
  5. Active mode 缺點:由於數據傳輸 port 是由 client 指定,一般 server 都有防火牆,不太可能打開所有 1024 以上的 ports。
  6. Passive mode
    1. FTP client 開啟一個隨機選擇的 TCP port 呼叫 FTP server 的 port 21 請求連線,並完成命令通道的建立。
    2. client 送一個 PASV command 給 server,要求進入 passive 傳輸模式。
    3. server (依設定範圍)隨機選一個 TCP port ,用命令通道告訴 client。
    4. client 呼叫剛才 server 告知的 TCP port 建立數據通道。此時封包帶 SYN flag。
    5. server 確認後回應一個 ACK 封包。完成所有交握手續並成功建立數據通道。
    6. 開始數據傳送。