title: Using python to find the file size of files on a ftp
body: <p>I'm new to python and I'm trying to read an ftp directory and write the filenames and file sizes to a file (currently a text file)</p>
  
  <pre><code>import sys
  import os
  import ftplib
  import ftputil
  import fnmatch
  log = open("C:/..../ftp_name.txt","a")
  print "logging into FTP" # print 
  host = ftputil.FTPHost('address','Uname','Pass') # ftp host info
  recursive = host.walk("/WORLDVIEW",topdown=True,onerror=None) # recursive search 
  for root,dirs,files in recursive:
      for name in files:
          fullpath = os.path.join(root, name)
          size = FTP.size(fullpath)
          writepath = fullpath + " " +size + "\n"
          log.write(writepath)
  </code></pre>
  
  <p>I got it to write the filename and path but once I added the size function in it went wrong</p>
  
  <p>The error I received was:</p>
  
  <pre><code>&lt;b&gt;NameError: name 'FTP' is not defined&lt;/b&gt;
  </code></pre>
  
  <p>I have also tried replacing</p>
  
  <pre><code>size = FTP.size(fullpath)
  </code></pre>
  
  <p>with</p>
  
  <pre><code>size = recursive.size(fullpath)
  </code></pre>
  
  <p>which returned the error:</p>
  
  <pre><code>&lt;b&gt;AttributeError: 'generator' object has no attribute 'size'&lt;/b&gt;
  </code></pre>