title: Using Channels with Paramiko
body: <p>I am working on converting a tool from Ruby to Python, and the Ruby version uses <a href="http://www.rubydoc.info/github/net-ssh/net-ssh/Net/SSH" rel="nofollow noreferrer">Net::SSH</a> to connect to a remote host, and send commands and retrieve responses/data. I have been using paramiko in the Python counterpart, but I'm confused as to the purpose of <a href="http://docs.paramiko.org/en/2.1/api/channel.html" rel="nofollow noreferrer">Channels in paramiko.</a> From what I've read so far, it seems to me that a channel (which uses a <a href="http://docs.paramiko.org/en/2.1/api/transport.html#paramiko.transport.Transport" rel="nofollow noreferrer">paramiko Transport</a>) is used to keep a persistent connection to SSH rather than executing a command and then terminating the connection. </p>
  
  <p>Is a Channel required? What is the stack required to open a persistent SSH connection to a host as to send and receive multiple commands sequentially and get the responses, then when finished manually close the connection?</p>
  
  <p>These are the two main lines I'm having trouble translating into Python, because I'm not sure if a Ruby "Channel" directly maps to a paramiko "Channel":</p>
  
  <pre><code>@ssh_connection = Net::SSH.start(@linux_server_name, 
                          @server_user_name, 
                          :password =&gt; @password, 
                          :paranoid =&gt; false)
  </code></pre>
  
  <p>and later on in the code</p>
  
  <pre><code>@channel = @ssh_connection.open_channel do |new_channel|
  </code></pre>
  
  <p><strong>Edit:</strong> To further explain my question, I was able to connect to a remote host using paramiko and execute multiple sequential commands and get their results without using a transport or a channel, so again, what are the reasons for using a Channel in paramiko?</p>
  
  <pre><code>def connect(self):
      ssh_connection = paramiko.SSHClient()
      ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
      ssh_connection.connect(self.linux_server_name)
      stdin, stdout, stderr = ssh_connection.exec_command("ls -l")
      print(stdout.readlines())
      stdin, stdout, stderr = ssh_connection.exec_command("ls -l /tmp")
      print(stdout.readlines())
      ssh_connection.close()
  </code></pre>