diff --git a/CHANGELOG.md b/CHANGELOG.md index b36f9a95..d92e0ec6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `MemFS` now immediately releases all memory it holds when `close()` is called, rather than when it gets garbage collected. Closes [issue #308](https://github.com/PyFilesystem/pyfilesystem2/issues/308). +- `FTPFS` now translates `EOFError` into `RemoteConnectionError`. Closes [#292](https://github.com/PyFilesystem/pyfilesystem2/issues/292) ## [2.4.8] - 2019-06-12 diff --git a/fs/ftpfs.py b/fs/ftpfs.py index 8e295da4..21e98a10 100644 --- a/fs/ftpfs.py +++ b/fs/ftpfs.py @@ -77,6 +77,8 @@ def ftp_errors(fs, path=None): raise errors.RemoteConnectionError( msg="unable to connect to {}".format(fs.host) ) + except EOFError: + raise errors.RemoteConnectionError(msg="lost connection to {}".format(fs.host)) except error_temp as error: if path is not None: raise errors.ResourceError( diff --git a/tests/test_ftpfs.py b/tests/test_ftpfs.py index df6c97a7..19ce22ed 100644 --- a/tests/test_ftpfs.py +++ b/tests/test_ftpfs.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import socket -import ftplib import os import platform import shutil @@ -114,6 +113,20 @@ def test_manager(self): with ftp_errors(mem_fs): raise error_perm("999 foo") + def test_manager_with_host(self): + mem_fs = open_fs("mem://") + mem_fs.host = "ftp.example.com" + + with self.assertRaises(errors.RemoteConnectionError) as err_info: + with ftp_errors(mem_fs): + raise EOFError + self.assertEqual(str(err_info.exception), "lost connection to ftp.example.com") + + with self.assertRaises(errors.RemoteConnectionError) as err_info: + with ftp_errors(mem_fs): + raise socket.error + self.assertEqual(str(err_info.exception), "unable to connect to ftp.example.com") + @attr("slow") class TestFTPFS(FSTestCases, unittest.TestCase): @@ -167,7 +180,7 @@ def tearDown(self): def test_ftp_url(self): self.assertEqual(self.fs.ftp_url, "ftp://{}:{}@{}:{}".format(self.user, self.pasw, self.server.host, self.server.port)) - + def test_geturl(self): self.fs.makedir("foo") self.fs.create("bar") @@ -251,7 +264,7 @@ def make_fs(self): def test_features(self): pass - + @attr("slow") class TestAnonFTPFS(FSTestCases, unittest.TestCase):