0

Need to process files from an FTP connection without downloading all of the files. What is the equivalent 'open' method for FTP so I can open the contents of the file, read the file into a large repository file, and discard of the file and it's contents?

import ftplib
repofile = open('repofile.txt', 'w')
ftp = ftplib.FTP('severaddress', 'username', 'password')
ftp.cwd('directory/I/want')
filelist = ftp.nlst()
''' above line creates a list of the files to loop through'''

for file in filelist:
    # open file, but don't download it
    # write contents to repofile
Lisle
  • 1,620
  • 2
  • 16
  • 22
  • Your question is somewhat contradictory: a local program must, at some point, copy all the contents of a file it's processing. Is your question that you don't want to save the remote file locally before processing, but rather hold it in memory? – Nathaniel Ford Mar 10 '16 at 18:38
  • Good point. Yes, I would rather it be in memory, work through the contents, then be discarded once contents are written to repofile. Thanks for clarifying. – Lisle Mar 10 '16 at 18:40
  • Ok, then you probably want this: http://stackoverflow.com/questions/1596963/read-a-file-from-server-with-ssh-using-python – Nathaniel Ford Mar 10 '16 at 18:41
  • Is there no way to perform this via FTP? Without installing paramiko? – Lisle Mar 10 '16 at 18:55
  • http://stackoverflow.com/questions/18772703/read-a-file-in-buffer-from-ftp-python Really, you should be searching 'open remote file in python'. The ftplib package should do you fine. The documentation is here: https://docs.python.org/2/library/ftplib.html – Nathaniel Ford Mar 10 '16 at 18:56

0 Answers0