title: Copy files in ftp server Python
body: <p>I was able to copy files in the ftp server to a different location by writing the file to the webserver and then uploading it again. </p>
  
  <p>Is there any way that I can write the file contents to memory without writing it to the harddisk and uploading them to the server. This is my code.</p>
  
  <pre><code>filepath = os.path.join(os.path.dirname(os.path.dirname(__file__)),'OpenTable','tempfiles')
  
  ftp = ftplib.FTP('ftphost')
  ftp.login('username','password')
  filenames = []
  ftp.retrlines('NLST', filenames.append)
  for filename in filenames:
  
      if filename[len(filename)-3:] == 'zip':
  
          ftp.cwd("/")
          filepath1 = os.path.join(filepath,filename)
          print filepath1
          r = open(filepath1,'w')
  
          ftp.retrbinary('RETR ' + filename, r.write)
          ftp.cwd("/BackUp")
          r.close()
          r = open(filepath1,'r')
  
          ftp.storbinary('STOR ' + filename, r)
          r.close()
          os.remove(filepath1)
          print 'Successfully Backed up ', filename
  ftp.quit()
  </code></pre>
  
  <p>I tried using the StringIO. It doesn't seem to work.</p>
  
  <p>Thanks.</p>