Skip to content

Commit

Permalink
[ftp] Add FTP_STORAGE_ENCODING setting (#803)
Browse files Browse the repository at this point in the history
* Added utf-8 support

* Added FTP_STORAGE_ENCODING setting
  • Loading branch information
AlexElizard authored Feb 7, 2020
1 parent 5d541a9 commit ec9579b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/backends/ftp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ Settings

``BASE_URL``
URL that serves the files stored at this location. Defaults to the value of your ``MEDIA_URL`` setting.

Optional parameters
~~~~~~~~~~~~~~~~~~~

``ENCODING``
File encoding. Example ``'utf-8'``. Default value ``'latin-1'``
4 changes: 3 additions & 1 deletion storages/backends/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ class FTPStorageException(Exception):
class FTPStorage(Storage):
"""FTP Storage class for Django pluggable storage system."""

def __init__(self, location=None, base_url=None):
def __init__(self, location=None, base_url=None, encoding=None):
location = location or setting('FTP_STORAGE_LOCATION')
if location is None:
raise ImproperlyConfigured("You must set a location at "
"instanciation or at "
" settings.FTP_STORAGE_LOCATION'.")
self.location = location
self.encoding = encoding or setting('FTP_STORAGE_ENCODING') or 'latin-1'
base_url = base_url or settings.MEDIA_URL
self._config = self._decode_location(location)
self._base_url = base_url
Expand Down Expand Up @@ -88,6 +89,7 @@ def _start_connection(self):
# Real reconnect
if self._connection is None:
ftp = ftplib.FTP()
ftp.encoding = self.encoding
try:
ftp.connect(self._config['host'], self._config['port'])
ftp.login(self._config['user'], self._config['passwd'])
Expand Down

0 comments on commit ec9579b

Please sign in to comment.