title: AttributeError: 'module' object has no attribute 'nlst'
body: <p>I am trying to put this into def statments:</p>
  
  <pre><code>#!/usr/bin/env python
  
  import ftplib
  import os
  import sys
  import paramiko
  import datetime
  import pickle
  
  username = "ftp1"
  password = "pass"
  
  
  try:
          try:
              print "Connecting to 0.0.0.0"
              ftp = ftplib.FTP("0.0.0.0")
              ftp.login(username, password)
              ftp.cwd('Dir')
  
          except ftplib.all_errors as e:
              print(e)
  except ftp.login as s:
      print (s)
  
  files = []
  
  try:
          files = ftp.nlst()
  except ftplib.error_perm, resp:
     if str(resp) == "550 No files found":
          print "No files in this directory"
     else:
          raise
  
  for f in files:
     print f
  </code></pre>
  
  <p>----------------------revised--------------------------</p>
  
  <pre><code>#!/usr/bin/env python
  
  import ftplib
  import os
  import sys
  import paramiko
  import datetime
  import pickle
  import ftplib as ftp
  
  
  hostname = "0.0.0.0"
  password = "pass"
  username = "ftp1"
  
  def connect():
      try:
          print "Connecting to 0.0.0.0"
          ftp = ftplib.FTP("0.0.0.0")
          ftp.login(username, password)
  
      except ftplib.all_errors as e:
          print(e)
  
  connect()
  
  
  def list_files():
  
      files = []
  
      try:
               files = ftp.nlst()
      except ftplib.error_perm, resp:
          if str(resp) == "550 No files found":
              print "No files in this directory"
          else:
               raise
  
      for f in files:
         print f
  
  list_files()
  </code></pre>
  
  <hr>
  
  <p>Successful with the first function created:</p>
  
  <pre><code>def connect():
      try:
          print "Connecting to 0.0.0.0"
          ftp = ftplib.FTP("0.0.0.0")
          ftp.login(username, password)
  
      except ftplib.all_errors as e:
          print(e)
  
  connect()
  </code></pre>
  
  <p>-----------------------get error on second def statement----------------</p>
  
  <pre><code>def list_files():
  
      files = []
  
      try:
               files = ftp.nlst()
      except ftplib.error_perm, resp:
          if str(resp) == "550 No files found":
              print "No files in this directory"
          else:
               raise
  
      for f in files:
         print f
  
  list_files()
  </code></pre>
  
  <p>====================<strong><em>AttributeError: 'module' object has no attribute 'nlst'</em></strong>============</p>
  
  <p>Please help me understand what I am missing here.... I am sure it is something simple.... but I am missing it....</p>