Transfers a file from a FTP server to another FTP server. The source file is on an other FTP server (FXP). NOTICE: The file is directly transferred from one server to the other server. @param[in] SourceFtpServer A FTP server from which the file which is copied. @param[in] strSourceFile Name of the file which is on the source FTP server. @param[in] TargetFtpServer A FTP server to which the file is
| 819 | /// @param[in] repType Representation Type (see documentation of CRepresentation) |
| 820 | /// @param[in] fPasv see documentation of CFTPClient::Passive |
| 821 | /*static*/ bool CFTPClient::TransferFile(const CFTPClient& SourceFtpServer, const tstring& strSourceFile, |
| 822 | const CFTPClient& TargetFtpServer, const tstring& strTargetFile, |
| 823 | const CRepresentation& repType/*=CRepresentation(CType::Image())*/, |
| 824 | bool fSourcePasv/*=false*/) |
| 825 | { |
| 826 | // transmit representation to server |
| 827 | if( SourceFtpServer.RepresentationType(repType)!=FTP_OK ) |
| 828 | return false; |
| 829 | |
| 830 | if( TargetFtpServer.RepresentationType(repType)!=FTP_OK ) |
| 831 | return false; |
| 832 | |
| 833 | const CFTPClient& PassiveServer = fSourcePasv ? SourceFtpServer : TargetFtpServer; |
| 834 | const CFTPClient& ActiveServer = fSourcePasv ? TargetFtpServer : SourceFtpServer; |
| 835 | |
| 836 | // set one FTP server in passive mode |
| 837 | // the FTP server opens a port and tell us the socket (ip address + port) |
| 838 | // this socket is used for opening the data connection |
| 839 | ULONG ulIP = 0; |
| 840 | USHORT ushSock = 0; |
| 841 | if( PassiveServer.Passive(ulIP, ushSock)!=FTP_OK ) |
| 842 | return false; |
| 843 | |
| 844 | CSockAddr csaPassiveServer(ulIP, ushSock); |
| 845 | |
| 846 | // transmit the socket (ip address + port) of the first FTP server to the |
| 847 | // second server |
| 848 | // the second FTP server establishes then the data connection to the first |
| 849 | if( ActiveServer.DataPort(csaPassiveServer.DottedDecimal(), ushSock)!=FTP_OK ) |
| 850 | return false; |
| 851 | |
| 852 | if( !SourceFtpServer.SendCommand(CCommand::RETR(), strSourceFile) ) |
| 853 | return false; |
| 854 | |
| 855 | CReply ReplyTarget; |
| 856 | if( !TargetFtpServer.SendCommand(CCommand::STOR(), strTargetFile, ReplyTarget) || |
| 857 | !ReplyTarget.Code().IsPositivePreliminaryReply() ) |
| 858 | return false; |
| 859 | |
| 860 | CReply ReplySource; |
| 861 | if( !SourceFtpServer.GetResponse(ReplySource) || !ReplySource.Code().IsPositivePreliminaryReply() ) |
| 862 | return false; |
| 863 | |
| 864 | // get response from FTP servers |
| 865 | if( !SourceFtpServer.GetResponse(ReplySource) || !ReplySource.Code().IsPositiveCompletionReply() || |
| 866 | !TargetFtpServer.GetResponse(ReplyTarget) || !ReplyTarget.Code().IsPositiveCompletionReply() ) |
| 867 | return false; |
| 868 | |
| 869 | return true; |
| 870 | } |
| 871 | |
| 872 | /// Executes a commando that result in a communication over the data port. |
| 873 | /// @param[in] crDatachannelCmd Command to be executeted. |
nothing calls this directly
no test coverage detected