Server Administration

  Home arrow Server Administration arrow Page 2 - SSH Case Studies: The Passive Mode

SSH Case Studies: The Passive Mode
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0

    Table of Contents:
  • SSH Case Studies: The Passive Mode
  • 11.2.5 FTP, Firewalls, and Passive Mode



    SSH Case Studies: The Passive Mode - 11.2.5 FTP, Firewalls, and Passive Mode

    (Page 2 of 2 )

    Recall that in active mode, the FTP data connections go in the opposite direction than you might expect—from the server back to the client. This usual mode of operation (shown in Figure 11-4) often develops problems in the presence of a firewall. Suppose the client is behind a firewall that allows all outbound connections but restricts inbound ones. Then the client can establish a control connection to log in and issue commands, but data-transfer commands such as ls, get, and put will fail, because the firewall blocks the data connections coming back to the client machine. Simple packet-filtering firewalls can’t be configured to allow these connections, because they appear as separate TCP destinations to random ports, with no obvious relation to the established FTP control connection.* The failure might happen

    quickly with the message “connection refused,” or the connection might hang for a while and eventually fail. This depends on whether the firewall explicitly rejects the connection attempt with an ICMP or TCP RST message, or just silently drops the packets. Note that this problem can occur whether or not SSH is forwarding the control connection.

    Figure 11-4. FTP client behind a firewall

    Passive mode usually solves this problem, reversing the direction of data connections so they go from the client to the server. Unfortunately, not all FTP client or servers implement passive-mode transfers. Command-line FTP clients generally use thepassivecommand to toggle passive-mode transfers on and off; if it doesn’t recognize that command, it probably doesn’t do passive mode. If the client supports passive mode but the server doesn’t, you may see a message like “PASV: command not understood” from the server.PASVis the FTP protocol command that instructs the server to listen for data connections. Finally, even if passive mode solves the firewall problem, it doesn’t help with SSH forwarding, since the ports in question are still dynamically chosen.

    Here is an example of the firewall problem, blocking the return data connections:

    $ ftp
    Connected to
    220 ProFTPD 1.2.0pre6 Server (Lasciate FTP Server)[]
    331 Password required for slade.
    230 User slade logged in.
    Remote system type is UNIX.
    Using binary mode to transfer files.
    ftp> ls
    200 PORT command successful.
    [...long wait here...]
    425 Can't build data connection: Connection timed out

    Passive mode comes to the rescue:

    ftp> passive
    Passive mode on.
    ftp> ls
    227 Entering Passive Mode (10,25,15,1,12,65)
    150 Opening ASCII mode data connection for file list
    drwxr-x--x 21 slade web 2048 May 8 23:29 .
    drwxr-xr-x 111 root wheel 10240 Apr 26 00:09 ..
    -rw------- 1 slade other 106 May 8 15:22 .cshrc
    -rw------- 1 slade other 31384 Aug 18 1997 .emacs
    226 Transfer complete.

    Now, in discussing the problem of using FTP through a firewall, we didn’t mention SSH at all; it is a problem inherent in the FTP protocol and firewalls. However, even when forwarding the FTP control connection through SSH, this problem still applies, since the difficulty is with the data connection, not the control, and those don’t go through SSH. So, this is yet another reason why you will normally want to use passive mode with FTP and SSH.

    Please check back next week for the next part of the series. 

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus


    - SSH Case Studies: Gateway Hosts
    - SSH Case Studies: More on Pine and SSH
    - SSH Case Studies: Pine and IMAP
    - SSH Case Studies: More on the Passive Mode
    - SSH Case Studies: Network Address Translation
    - SSH Case Studies: The Passive Mode
    - SSH Case Studies: The FTP Protocol
    - SSH Case Studies: Batch Jobs, FTP and SSH
    - SSH Case Studies: Agents and Authentication
    - SSH Case Studies
    - Server Responses to Client Communication
    - Authentication in Client/Server Communication
    - Client/Server Communication
    - Understanding Awk in the UNIX Shell
    - Stream Editor in the UNIX Shell

    Developer Shed Affiliates


    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap