|
@@ -66,9 +66,9 @@ FtpConnection::FtpConnection(cuid_t cuid, const SocketHandle& socket,
|
|
|
const SharedHandle<Request>& req,
|
|
|
const SharedHandle<AuthConfig>& authConfig,
|
|
|
const Option* op):
|
|
|
- cuid(cuid), socket(socket), req(req),
|
|
|
- _authConfig(authConfig), option(op),
|
|
|
- logger(LogFactory::getInstance()),
|
|
|
+ _cuid(cuid), _socket(socket), _req(req),
|
|
|
+ _authConfig(authConfig), _option(op),
|
|
|
+ _logger(LogFactory::getInstance()),
|
|
|
_socketBuffer(socket),
|
|
|
_baseWorkingDir("/") {}
|
|
|
|
|
@@ -80,9 +80,9 @@ bool FtpConnection::sendUser()
|
|
|
std::string request = "USER ";
|
|
|
request += _authConfig->getUser();
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(),"USER ********");
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(),"USER ********");
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -96,9 +96,9 @@ bool FtpConnection::sendPass()
|
|
|
std::string request = "PASS ";
|
|
|
request += _authConfig->getPassword();
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(),"PASS ********");
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(),"PASS ********");
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -110,7 +110,7 @@ bool FtpConnection::sendType()
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
std::string type;
|
|
|
- if(option->get(PREF_FTP_TYPE) == V_ASCII) {
|
|
|
+ if(_option->get(PREF_FTP_TYPE) == V_ASCII) {
|
|
|
type = FtpConnection::A;
|
|
|
} else {
|
|
|
type = FtpConnection::I;
|
|
@@ -118,9 +118,9 @@ bool FtpConnection::sendType()
|
|
|
std::string request = "TYPE ";
|
|
|
request += type;
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(),request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(),request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -132,9 +132,9 @@ bool FtpConnection::sendPwd()
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
std::string request = "PWD\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(),request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(),request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -145,19 +145,19 @@ bool FtpConnection::sendPwd()
|
|
|
bool FtpConnection::sendCwd()
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
- if(logger->info()) {
|
|
|
- logger->info("CUID#%s - Using base working directory '%s'",
|
|
|
- util::itos(cuid).c_str(), _baseWorkingDir.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info("CUID#%s - Using base working directory '%s'",
|
|
|
+ util::itos(_cuid).c_str(), _baseWorkingDir.c_str());
|
|
|
}
|
|
|
std::string request = "CWD ";
|
|
|
if(_baseWorkingDir != "/") {
|
|
|
request += _baseWorkingDir;
|
|
|
}
|
|
|
- request += util::percentDecode(req->getDir());
|
|
|
+ request += util::percentDecode(_req->getDir());
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(),request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(),request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -169,11 +169,11 @@ bool FtpConnection::sendMdtm()
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
std::string request = "MDTM ";
|
|
|
- request += util::percentDecode(req->getFile());
|
|
|
+ request += util::percentDecode(_req->getFile());
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(), request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(), request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -185,11 +185,11 @@ bool FtpConnection::sendSize()
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
std::string request = "SIZE ";
|
|
|
- request += util::percentDecode(req->getFile());
|
|
|
+ request += util::percentDecode(_req->getFile());
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(), request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(), request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -201,9 +201,9 @@ bool FtpConnection::sendPasv()
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
static const std::string request("PASV\r\n");
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(), request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(), request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -224,7 +224,7 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
std::pair<std::string, uint16_t> addrinfo;
|
|
|
- socket->getAddrInfo(addrinfo);
|
|
|
+ _socket->getAddrInfo(addrinfo);
|
|
|
unsigned int ipaddr[4];
|
|
|
sscanf(addrinfo.first.c_str(), "%u.%u.%u.%u",
|
|
|
&ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
|
|
@@ -242,9 +242,9 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
|
|
|
request += ",";
|
|
|
request += util::uitos(addrinfo.second%256);
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(), request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(), request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -262,9 +262,9 @@ bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
|
|
|
request += util::itos(segment->getPositionToWrite());
|
|
|
}
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(), request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(), request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -276,11 +276,11 @@ bool FtpConnection::sendRetr()
|
|
|
{
|
|
|
if(_socketBuffer.sendBufferIsEmpty()) {
|
|
|
std::string request = "RETR ";
|
|
|
- request += util::percentDecode(req->getFile());
|
|
|
+ request += util::percentDecode(_req->getFile());
|
|
|
request += "\r\n";
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_SENDING_REQUEST,
|
|
|
- util::itos(cuid).c_str(), request.c_str());
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_SENDING_REQUEST,
|
|
|
+ util::itos(_cuid).c_str(), request.c_str());
|
|
|
}
|
|
|
_socketBuffer.pushStr(request);
|
|
|
}
|
|
@@ -343,28 +343,29 @@ FtpConnection::findEndOfResponse(unsigned int status,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool FtpConnection::bulkReceiveResponse(std::pair<unsigned int, std::string>& response)
|
|
|
+bool FtpConnection::bulkReceiveResponse
|
|
|
+(std::pair<unsigned int, std::string>& response)
|
|
|
{
|
|
|
char buf[1024];
|
|
|
- while(socket->isReadable(0)) {
|
|
|
+ while(_socket->isReadable(0)) {
|
|
|
size_t size = sizeof(buf);
|
|
|
- socket->readData(buf, size);
|
|
|
+ _socket->readData(buf, size);
|
|
|
if(size == 0) {
|
|
|
- if(socket->wantRead() || socket->wantWrite()) {
|
|
|
+ if(_socket->wantRead() || _socket->wantWrite()) {
|
|
|
return false;
|
|
|
}
|
|
|
throw DL_RETRY_EX(EX_GOT_EOF);
|
|
|
}
|
|
|
- if(strbuf.size()+size > MAX_RECV_BUFFER) {
|
|
|
+ if(_strbuf.size()+size > MAX_RECV_BUFFER) {
|
|
|
throw DL_RETRY_EX
|
|
|
(StringFormat("Max FTP recv buffer reached. length=%lu",
|
|
|
- static_cast<unsigned long>(strbuf.size()+size)).str());
|
|
|
+ static_cast<unsigned long>(_strbuf.size()+size)).str());
|
|
|
}
|
|
|
- strbuf.append(&buf[0], &buf[size]);
|
|
|
+ _strbuf.append(&buf[0], &buf[size]);
|
|
|
}
|
|
|
unsigned int status;
|
|
|
- if(strbuf.size() >= 4) {
|
|
|
- status = getStatus(strbuf);
|
|
|
+ if(_strbuf.size() >= 4) {
|
|
|
+ status = getStatus(_strbuf);
|
|
|
if(status == 0) {
|
|
|
throw DL_ABORT_EX(EX_INVALID_RESPONSE);
|
|
|
}
|
|
@@ -372,14 +373,14 @@ bool FtpConnection::bulkReceiveResponse(std::pair<unsigned int, std::string>& re
|
|
|
return false;
|
|
|
}
|
|
|
std::string::size_type length;
|
|
|
- if((length = findEndOfResponse(status, strbuf)) != std::string::npos) {
|
|
|
+ if((length = findEndOfResponse(status, _strbuf)) != std::string::npos) {
|
|
|
response.first = status;
|
|
|
- response.second = strbuf.substr(0, length);
|
|
|
- if(logger->info()) {
|
|
|
- logger->info(MSG_RECEIVE_RESPONSE,
|
|
|
- util::itos(cuid).c_str(), response.second.c_str());
|
|
|
+ response.second = _strbuf.substr(0, length);
|
|
|
+ if(_logger->info()) {
|
|
|
+ _logger->info(MSG_RECEIVE_RESPONSE,
|
|
|
+ util::itos(_cuid).c_str(), response.second.c_str());
|
|
|
}
|
|
|
- strbuf.erase(0, length);
|
|
|
+ _strbuf.erase(0, length);
|
|
|
return true;
|
|
|
} else {
|
|
|
// didn't receive response fully.
|
|
@@ -459,12 +460,14 @@ unsigned int FtpConnection::receiveMdtmResponse(Time& time)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-unsigned int FtpConnection::receivePasvResponse(std::pair<std::string, uint16_t>& dest)
|
|
|
+unsigned int FtpConnection::receivePasvResponse
|
|
|
+(std::pair<std::string, uint16_t>& dest)
|
|
|
{
|
|
|
std::pair<unsigned int, std::string> response;
|
|
|
if(bulkReceiveResponse(response)) {
|
|
|
if(response.first == 227) {
|
|
|
- // we assume the format of response is "227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)."
|
|
|
+ // we assume the format of response is "227 Entering Passive
|
|
|
+ // Mode (h1,h2,h3,h4,p1,p2)."
|
|
|
unsigned int h1, h2, h3, h4, p1, p2;
|
|
|
std::string::size_type p = response.second.find("(");
|
|
|
if(p >= 4) {
|