Issue #74 open

ftp backend has many bugs

Anonymous avatarAnonymous created an issue

Hi,

Many trivial bugs on ftp backend, see the patch.

David

diff -r 0181134a8edb storages/backends/ftp.py
--- a/storages/backends/ftp.py  Wed Mar 09 13:55:16 2011 +0100
+++ b/storages/backends/ftp.py  Wed Mar 09 17:57:30 2011 +0100
@@ -61,6 +61,9 @@
         
         return config
 
+    def _end_connection(self):
+        self.disconnect()
+
     def _start_connection(self):
         # Check if connection is still alive and if not, drop it.
         if self._connection is not None:
@@ -89,6 +92,8 @@
         self._connection = None
 
     def _mkremdirs(self, path):
+        if (path) == '':
+            return
         pwd = self._connection.pwd()
         path_splitted = path.split('/')
         for path_part in path_splitted:
@@ -105,11 +110,14 @@
 
     def _put_file(self, name, content):
         # Connection must be open!
-        try:
-            self._mkremdirs(os.path.dirname(name))
+       try:
             pwd = self._connection.pwd()
-            self._connection.cwd(os.path.dirname(name))
-            self._connection.storbinary('STOR ' + os.path.basename(name), content.file, content.DEFAULT_CHUNK_SIZE)
+            if os.path.dirname(name) != '':
+                self._mkremdirs(os.path.dirname(name))
+                self._connection.cwd(os.path.dirname(name))
+            memory_file = StringIO(content)
+            self._connection.storbinary('STOR ' + os.path.basename(name), memory_file, 8*1024)
+            memory_file.close()
             self._connection.cwd(pwd)
         except ftplib.all_errors, e:
             raise FTPStorageException('Error writing file %s' % name)
@@ -241,4 +249,4 @@
             self._storage._start_connection()
             self._storage._put_file(self._name, self.file.getvalue())
             self._storage._end_connection()
-        self.file.close()
\ No newline at end of file
+        self.file.close()


Comments (3)

  1. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.