Opens an active data connection. @param[out] sckDataConnection @param[in] crDatachannelCmd Command to be executeted. @param[in] strPath Parameter for the command usually a path. @param[in] dwByteOffset Server marker at which file transfer is to be restarted.
| 950 | /// @param[in] strPath Parameter for the command usually a path. |
| 951 | /// @param[in] dwByteOffset Server marker at which file transfer is to be restarted. |
| 952 | bool CFTPClient::OpenActiveDataConnection(IBlockingSocket& sckDataConnection, const CCommand& crDatachannelCmd, const tstring& strPath, DWORD dwByteOffset) const |
| 953 | { |
| 954 | if( !crDatachannelCmd.IsDatachannelCommand() ) |
| 955 | { |
| 956 | ASSERT(false); |
| 957 | return false; |
| 958 | } |
| 959 | |
| 960 | std::unique_ptr<IBlockingSocket> apSckServer(m_apSckControlConnection->CreateInstance()); |
| 961 | |
| 962 | USHORT ushLocalSock = 0; |
| 963 | try |
| 964 | { |
| 965 | // INADDR_ANY = ip address of localhost |
| 966 | // second parameter "0" means that the WINSOCKAPI ask for a port |
| 967 | CSockAddr csaAddressTemp(INADDR_ANY, 0); |
| 968 | apSckServer->Create(SOCK_STREAM); |
| 969 | apSckServer->Bind(csaAddressTemp); |
| 970 | apSckServer->GetSockAddr(csaAddressTemp); |
| 971 | ushLocalSock=csaAddressTemp.Port(); |
| 972 | apSckServer->Listen(); |
| 973 | } |
| 974 | catch(CBlockingSocketException& blockingException) |
| 975 | { |
| 976 | ReportError(blockingException.GetErrorMessage(), CCnv::ConvertToTString(__FILE__), __LINE__); |
| 977 | apSckServer->Cleanup(); |
| 978 | return false; |
| 979 | } |
| 980 | |
| 981 | // get own ip address |
| 982 | CSockAddr csaLocalAddress; |
| 983 | m_apSckControlConnection->GetSockAddr(csaLocalAddress); |
| 984 | |
| 985 | // transmit the socket (ip address + port) to the server |
| 986 | // the FTP server establishes then the data connection |
| 987 | if( DataPort(csaLocalAddress.DottedDecimal(), ushLocalSock)!=FTP_OK ) |
| 988 | return false; |
| 989 | |
| 990 | // if resuming is activated then set offset |
| 991 | if( m_fResumeIfPossible && |
| 992 | (crDatachannelCmd==CCommand::STOR() || crDatachannelCmd==CCommand::RETR() || crDatachannelCmd==CCommand::APPE() ) && |
| 993 | (dwByteOffset!=0 && Restart(dwByteOffset)!=FTP_OK) ) |
| 994 | return false; |
| 995 | |
| 996 | // send FTP command RETR/STOR/NLST/LIST to the server |
| 997 | CReply Reply; |
| 998 | if( !SendCommand(crDatachannelCmd, strPath, Reply) || |
| 999 | !Reply.Code().IsPositivePreliminaryReply() ) |
| 1000 | return false; |
| 1001 | |
| 1002 | // accept the data connection |
| 1003 | CSockAddr sockAddrTemp; |
| 1004 | if( !apSckServer->Accept(sckDataConnection, sockAddrTemp) ) |
| 1005 | return false; |
| 1006 | |
| 1007 | return true; |
| 1008 | } |
| 1009 |
nothing calls this directly
no test coverage detected