Commits

Janusz Harkot  committed 016773c

ftp fixes

  • Participants
  • Parent commits e8acc6c

Comments (0)

Files changed (1)

File storages/backends/ftp.py

             if os.path.dirname(name) != '':
                 self._mkremdirs(os.path.dirname(name))
                 self._connection.cwd(os.path.dirname(name))
-            memory_file = StringIO(content)
+
+            wrap_data = False
+            if not hasattr(content, 'read'):
+                memory_file = StringIO(content)
+                wrap_data = True
+
             self._connection.storbinary('STOR ' + os.path.basename(name), memory_file, 8 * 1024)
-            memory_file.close()
+
+            if wrap_data:
+                memory_file.close()
+
             self._connection.cwd(pwd)
         except ftplib.all_errors, e:
             raise FTPStorageException('Error writing file %s' % name)