Copy file from one FTP-instance to another.
(source, sourcename, target, targetname = '', type = 'I')
| 877 | |
| 878 | |
| 879 | def ftpcp(source, sourcename, target, targetname = '', type = 'I'): |
| 880 | '''Copy file from one FTP-instance to another.''' |
| 881 | if not targetname: |
| 882 | targetname = sourcename |
| 883 | type = 'TYPE ' + type |
| 884 | source.voidcmd(type) |
| 885 | target.voidcmd(type) |
| 886 | sourcehost, sourceport = parse227(source.sendcmd('PASV')) |
| 887 | target.sendport(sourcehost, sourceport) |
| 888 | # RFC 959: the user must "listen" [...] BEFORE sending the |
| 889 | # transfer request. |
| 890 | # So: STOR before RETR, because here the target is a "user". |
| 891 | treply = target.sendcmd('STOR ' + targetname) |
| 892 | if treply[:3] not in {'125', '150'}: |
| 893 | raise error_proto # RFC 959 |
| 894 | sreply = source.sendcmd('RETR ' + sourcename) |
| 895 | if sreply[:3] not in {'125', '150'}: |
| 896 | raise error_proto # RFC 959 |
| 897 | source.voidresp() |
| 898 | target.voidresp() |
| 899 | |
| 900 | |
| 901 | def test(): |