title: IOError: [Errno 13] Permission denied - ftplib
body: <p>I am trying to download files from a ftp server but I am running into an error permission denied error. </p>
  
  <pre><code>Traceback (most recent call last):
     File "/Users/x34/Documents/Python/ftp_download.py", line 27, in &lt;module&gt;
       download()
     File "/Users/x34/Documents/Python/ftp_download.py", line 21, in download
       with open(filename,'wb') as f:
  IOError: [Errno 13] Permission denied: '/p012r018_5dt19900722_z20_30.tif.gz'
  </code></pre>
  
  <p>Downloading manually or with filezilla works fine but my script below does not</p>
  
  <pre><code>from ftplib import ftp    
  ftp = FTP(r'ftp.glcf.umd.edu')
  ftp.login()
  
  directory = 'glcf/Landsat/WRS2/p012/r018/p012r018_5dx19900722.TM-GLS1990'
  filename = '/p012r018_5dt19900722_z20_30.tif.gz'
  
  ftp.cwd(directory)
  
  with open(filename,'wb') as f:
      ftp.retrbinary('RETR' + filename,f.write)
  
  ftp.close()
  </code></pre>
  
  <p>One another note... and perhaps I misread the docs - <a href="http://docs.python.org/library/ftplib.html" rel="nofollow">http://docs.python.org/library/ftplib.html</a> but I do not fully understand where ftplib decides to download the files (default download directory?). Is there another module better suited for this application?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I should clarify that the filename on the server does not contain the '/' in front. I simply added that as it appeared to help locate the correct file location and name as prior attempts ended in the following error 
       ftplib.error_perm: 500 Unknown command. </p>
  
  <p>the full path to the file is</p>
  
  <pre><code> ftp.glcf.umd.edu/glcf/Landsat/WRS2/p012/r018/p012r018_5dx19900722.TM-GLS1990/p012r018_5dt19900722_z20_30.tif.gz'
  </code></pre>