Copy file from one FTP-instance to another.
(source, sourcename, target, targetname = '', type = 'I')
| 899 | |
| 900 | |
| 901 | def ftpcp(source, sourcename, target, targetname = '', type = 'I'): |
| 902 | '''Copy file from one FTP-instance to another.''' |
| 903 | if not targetname: |
| 904 | targetname = sourcename |
| 905 | type = 'TYPE ' + type |
| 906 | source.voidcmd(type) |
| 907 | target.voidcmd(type) |
| 908 | sourcehost, sourceport = parse227(source.sendcmd('PASV')) |
| 909 | target.sendport(sourcehost, sourceport) |
| 910 | # RFC 959: the user must "listen" [...] BEFORE sending the |
| 911 | # transfer request. |
| 912 | # So: STOR before RETR, because here the target is a "user". |
| 913 | treply = target.sendcmd('STOR ' + targetname) |
| 914 | if treply[:3] not in {'125', '150'}: |
| 915 | raise error_proto # RFC 959 |
| 916 | sreply = source.sendcmd('RETR ' + sourcename) |
| 917 | if sreply[:3] not in {'125', '150'}: |
| 918 | raise error_proto # RFC 959 |
| 919 | source.voidresp() |
| 920 | target.voidresp() |
| 921 | |
| 922 | |
| 923 | def test(): |