214
215
"""Copy the file-like or string object into the location.
216
217
:param relpath: Location to put the contents, relative to base.
217
:param f: File-like or string object.
218
:param fp: File-like or string object.
218
219
:param retries: Number of retries after temporary failures so far
219
220
for this operation.
221
222
TODO: jam 20051215 This should be an atomic put, not overwritting files in place
222
223
TODO: jam 20051215 ftp as a protocol seems to support chmod, but ftplib does not
225
tmp_abspath = '%s.tmp.%.9f.%d.%d' % (self._abspath(relpath), time.time(),
226
os.getpid(), random.randint(0,0x7FFFFFFF))
224
227
if not hasattr(fp, 'read'):
225
228
fp = StringIO(fp)
227
230
mutter("FTP put: %s" % self._abspath(relpath))
228
231
f = self._get_FTP()
229
f.storbinary('STOR '+self._abspath(relpath), fp, 8192)
233
f.storbinary('STOR '+tmp_abspath, fp)
234
f.rename(tmp_abspath, self._abspath(relpath))
235
except (ftplib.error_temp,EOFError), e:
237
f.delete(tmp_abspath)
230
241
except ftplib.error_perm, e:
231
242
if "no such file" in str(e).lower():
232
243
raise NoSuchFile("Error storing %s: %s"