とーますメモ

Ruby on Rails / Goなどの学習メモ

【FTP】FTPのパッシブモードについて

自分用メモ

Clientからパッシブモードで「FTPサーバ」に接続する場合は以下のようになるっぽい。

When Passive mode is used the Client first connects to the server on port 21. Then the client issues a PASV or EPSV command. The server then replies with an IP address and port number. The client finally uses that IP Address and port number to establish the data connection.

By Active and Passive FTP Transfers Defined

In step 1, the client contacts the server on the command port and issues the PASV command. The server then replies in step 2 with PORT 2024, telling the client which port it is listening to for the data connection. In step 3 the client then initiates the data connection from its data port to the specified server data port. Finally, the server sends back an ACK in step 4 to the client's data port.

By Active FTP vs. Passive FTP, a Definitive Explanation


1)[Client => FTP Server] 21番で接続し、ハンドシェイクし、コントロールコネクションを張る。

2)[FTP Server => Client] 自ら(FTP Server)のIP及びデータ転送に使用するポート番号をクライアントに返す

3)[Client => FTP Server] 2)で返ってきたIPとポート番号を元にデータコネクションを作る。

またパッシブモードは、コントロールコネクションもデータコネクションも「クライアントから」リクエストを送るため
クライアントサイドのFirewallの設定が楽になる。

「FTPS」の場合は、よくわからない・・・
FTP/SSL in passive mode with portrange, which ports has to be open on the firewall? - Server Fault


[参考]
FTPのアクティブモードとパッシブモードの違いは、データ転送の接続方向
How to Enable FTP Passive Mode - cPanel Knowledge Base - cPanel Documentation
アクティブFTPとパッシブFTP
centos - How to configure vsftpd to work with passive mode - Server Fault
Setting Up An FTPS Server Behind A Firewall or NAT For PASV Mode Data Transfers