MCPcopy Create free account
hub / github.com/Predelnik/DSpellCheck / OpenPassiveDataConnection

Method OpenPassiveDataConnection

deps/FtpClient/FTPClient.cpp:1015–1060  ·  view source on GitHub ↗

Opens a passive 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.

Source from the content-addressed store, hash-verified

1013/// @param[in] strPath Parameter for the command usually a path.
1014/// @param[in] dwByteOffset Server marker at which file transfer is to be restarted.
1015bool CFTPClient::OpenPassiveDataConnection(IBlockingSocket& sckDataConnection, const CCommand& crDatachannelCmd, const tstring& strPath, DWORD dwByteOffset) const
1016{
1017 if( !crDatachannelCmd.IsDatachannelCommand() )
1018 {
1019 ASSERT(false);
1020 return false;
1021 }
1022
1023 ULONG ulRemoteHostIP = 0;
1024 USHORT ushServerSock = 0;
1025
1026 // set passive mode
1027 // the FTP server opens a port and tell us the socket (ip address + port)
1028 // this socket is used for opening the data connection
1029 if( Passive(ulRemoteHostIP, ushServerSock)!=FTP_OK )
1030 return false;
1031
1032 // establish connection
1033 CSockAddr sockAddrTemp;
1034 try
1035 {
1036 sckDataConnection.Create(SOCK_STREAM);
1037 CSockAddr csaAddress(ulRemoteHostIP, ushServerSock);
1038 sckDataConnection.Connect(csaAddress);
1039 }
1040 catch(CBlockingSocketException& blockingException)
1041 {
1042 ReportError(blockingException.GetErrorMessage(), CCnv::ConvertToTString(__FILE__), __LINE__);
1043 sckDataConnection.Cleanup();
1044 return false;
1045 }
1046
1047 // if resuming is activated then set offset
1048 if( m_fResumeIfPossible &&
1049 (crDatachannelCmd==CCommand::STOR() || crDatachannelCmd==CCommand::RETR() || crDatachannelCmd==CCommand::APPE() ) &&
1050 (dwByteOffset!=0 && Restart(dwByteOffset)!=FTP_OK) )
1051 return false;
1052
1053 // send FTP command RETR/STOR/NLST/LIST to the server
1054 CReply Reply;
1055 if( !SendCommand(crDatachannelCmd, strPath, Reply) ||
1056 !Reply.Code().IsPositivePreliminaryReply() )
1057 return false;
1058
1059 return true;
1060}
1061
1062/// Sends data over a socket to the server.
1063/// @param[in] Observer Object for observing the execution of the command.

Callers

nothing calls this directly

Calls 6

IsDatachannelCommandMethod · 0.80
CreateMethod · 0.80
ConnectMethod · 0.80
GetErrorMessageMethod · 0.80
CleanupMethod · 0.80

Tested by

no test coverage detected