From: Tim Chase on
Matjaz Pfefferer wrote:
> What would be the easiest way to copy files from one ftp
> folder to another without downloading them to local system?

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




From: John Nagle on
Tim Chase wrote:
> Matjaz Pfefferer wrote:
>> What would be the easiest way to copy files from one ftp
>> folder to another without downloading them to local system?
>
> 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.

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
From: Tim Chase on
Simon wrote:
> You could user FTP.voidcmd()
> E.G.
> ftp.voidcmd('RNFT filename.txt')ftp.voidcmd('RNTO newdir/filename.txt')
>>From the rfc:
>
> RENAME FROM (RNFR)
>
> This command specifies the old pathname of the file which is
> to be renamed. This command must be immediately followed by
> a "rename to" command specifying the new file pathname.
>
> RENAME TO (RNTO)
>
> This command specifies the new pathname of the file
> specified in the immediately preceding "rename from"
> command. Together the two commands cause a file to be
> renamed.

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)




From: Anssi Saari on
John Nagle <nagle(a)animats.com> writes:

> 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.
From: John Nagle on
Anssi Saari wrote:
> John Nagle <nagle(a)animats.com> writes:
>
>> 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