title: IndexError: list index out of range while connecting to SFTP server using python
body: <p>i wrote a python script to connect to SFTP server using public key authentication. Code gets it server credentials from another text file called "config file" which is of format:</p>
  
  <p>IP,USERNAME</p>
  
  <p>IP2,USERNAME2</p>
  
  <p>when the config file contains more than 5 IP's and usernames it throws the error(see below). although it does not affect the output but whats the reason of the error and how to solve it or is there any better way to do it</p>
  
  <p>My Code:</p>
  
  <pre><code>import os
  import pysftp
  import socket
  import paramiko
  import time
  import os.path
  import shutil
  import pysftp
  import csv
  from pathlib import Path
  from stat import S_IMODE, S_ISDIR, S_ISREG
  
  cnopts = pysftp.CnOpts()
  cnopts.hostkeys=None
  
  import os
  
  privatekeyfile = os.path.expanduser("C:\\Users\\Rohan\\.ssh\\cool.prv")
  mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
  
  
  config_file_path = "config15.txt"     
  file = open(config_file_path, 'r')
  reader = csv.reader(file)
  all_rows = [row for row in reader]
  for line in all_rows:
      server_ip = line[0]
      username = line[1]
      with pysftp.Connection(host=server_ip, username=username, private_key=mykey, cnopts=cnopts) as sftp:
          r = (socket.gethostbyaddr(server_ip))
          print("connection successful with ", r)
  </code></pre>
  
  <p>Output and Error:(if there are 10 IP's in the config file)</p>
  
  <pre><code>connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  connection successful with  ('lootera', [], ['127.0.0.1'])
  Traceback (most recent call last):
    File "C:/Users/Rohan/PycharmProjects/untitled1/m.py", line 30, in &lt;module&gt;
      server_ip = line[0]
  IndexError: list index out of range
  connection successful with  ('lootera', [], ['127.0.0.1'])
  </code></pre>