As best I can tell, this isn't well-supported by FTP[1] which
doesn't seem to have a native "copy this file from
server-location to server-location bypassing the client".
There's a pair of RNFR/RNTO commands that allow you to rename (or
perhaps move as well) a file which ftplib.FTP.rename() supports
but it sounds like you want too copies.
When I've wanted to do this, I've used a non-FTP method, usually
SSH'ing into the server and just using "cp". This could work for
you if you have pycrypto/paramiko installed.
Your last hope would be that your particular FTP server has some
COPY extension that falls outside of RFC parameters -- something
that's not a portable solution, but if you're doing a one-off
script or something in a controlled environment, could work.
Otherwise, you'll likely be stuck slurping the file down just to
send it back up.
-tkc
[1]
http://en.wikipedia.org/wiki/List_of_FTP_commands
In theory, the FTP spec supports "three-way transfers", where the
source, destination, and control can all be on different machines.
But no modern implementation supports that.
John Nagle
As mentioned in my original reply, that should be what
ftplib.FTP.rename() does under the covers[1]. However, the OP
was asking about copying a file, not renaming a file.
John mentioned the poorly-supported "server-to-server copy", but
from my understanding, I think that still slurps locally and then
pushes it back up elsewhere.
-tkc
[1]
taken from ftplib.py:
def rename(self, fromname, toname):
'''Rename a file.'''
resp = self.sendcmd('RNFR ' + fromname)
if resp[0] != '3':
raise error_reply, resp
return self.voidcmd('RNTO ' + toname)
> In theory, the FTP spec supports "three-way transfers", where the
> source, destination, and control can all be on different machines.
> But no modern implementation supports that.
I remember even using that way back when, Unix machines in the 1990s.
But, server to server transfers are supported even today, since it's
part of the RFC. RFC959 explains how it's done in chapter 5.2. Usually
this is called FXP now.
http://en.wikipedia.org/wiki/Comparison_of_FTP_client_software lists a
bunch of clients with FXP support. I don't know about doing this with
ftplib, though.
Although the protocol allows setting up a 3-way transfer, many
FTP servers disallow data connections to an IP address different
from the control address. It's a security risk.
It's useful when you want to move data between machines with high
bandwidth connections, as within a server farm, and the control machine
has less bandwidth. But there are more modern approaches for that.
John Nagle
pyftpdlib supports it:
http://code.google.com/p/pyftpdlib/wiki/FAQ#What_is_FXP?
...but Python's ftplib.py module doesn't.
--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil