smart_open icon indicating copy to clipboard operation
smart_open copied to clipboard

Support for reading and writing files directly to/from ftp

Open RachitSharma2001 opened this issue 2 years ago • 2 comments

Title

Support for reading and writing files directly to/from ftp

Motivation

As elaborated in issue #33, there is currently no support for reading from ftp servers. With my change, developers will be able to read ftp files using smart open by doing the following:

from smart_open import open
with open('ftp://user:password@host:port/dir1/dir2/file') as fin:
     for line in fin:
          print(line)

Tests

Added test_ftp::FTPOpen

RachitSharma2001 avatar Sep 16 '22 19:09 RachitSharma2001

@mpenkov @petedannemann

Just to summarize the changes that I have made:

  1. I have added integration tests which bring up an FTP server and tests reading, writing and appending to it.
  2. I have created a wrapper around the file object returned by open("ftp://...") so that when the file is closed, the underlying socket is closed as well
  3. For bringing up the FTP server during ci tests, there doesn't seem to be any viable lightweight solutions, besides perhaps twisted.

Let me know if there is anything that you think should be changed or added.

RachitSharma2001 avatar Oct 01 '22 17:10 RachitSharma2001

@petedannemann Thank you! I have added your recommended changes. Let me know if you have any questions or if anything is confusing.

RachitSharma2001 avatar Oct 02 '22 19:10 RachitSharma2001

@mpenkov Do these changes look good to you?

RachitSharma2001 avatar Oct 16 '22 17:10 RachitSharma2001

@mpenkov Thank you for the suggestions. I have integrated the changes. Let me know if there is anything else that should be added.

RachitSharma2001 avatar Oct 17 '22 17:10 RachitSharma2001

Thank you for your work @RachitSharma2001 !!

mpenkov avatar Nov 03 '22 13:11 mpenkov