Commits

Anonymous committed e8acc6c

ftp fixes

Comments (0)

Files changed (1)

storages/backends/ftp.py

             except ftplib.all_errors, e:
                 raise FTPStorageException('Connection or login error using data %s' % repr(self._config))
 
+    def _end_connection(self):
+        self.disconnect()
+
     def disconnect(self):
         self._connection.quit()
         self._connection = None
 
     def _mkremdirs(self, path):
+        if (path) == '':
+            return
         pwd = self._connection.pwd()
         path_splitted = path.split('/')
         for path_part in path_splitted:
         try:
             self._mkremdirs(os.path.dirname(name))
             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)
             self._storage._start_connection()
             self._storage._put_file(self._name, self.file.getvalue())
             self._storage._end_connection()
-        self.file.close()
+        self.file.close()