/*
- * $Id: ftp.cc,v 1.382 2006/01/25 17:41:23 wessels Exp $
+ * $Id: ftp.cc,v 1.383 2006/01/26 00:22:18 wessels Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
void maybeReadData();
void transactionComplete();
void processReplyBody();
+ void FtpStateData::writeCommand(const char *buf);
static PF ftpSocketClosed;
static CNCB ftpPasvCallback;
return ret;
}
-static void
-ftpWriteCommand(const char *buf, FtpStateData * ftpState)
+void
+FtpStateData::writeCommand(const char *buf)
{
char *ebuf;
debug(9, 5) ("ftpWriteCommand: %s\n", buf);
else
ebuf = xstrdup(buf);
- safe_free(ftpState->ctrl.last_command);
+ safe_free(ctrl.last_command);
- safe_free(ftpState->ctrl.last_reply);
+ safe_free(ctrl.last_reply);
- ftpState->ctrl.last_command = ebuf;
+ ctrl.last_command = ebuf;
- comm_write(ftpState->ctrl.fd,
- ftpState->ctrl.last_command,
- strlen(ftpState->ctrl.last_command),
+ comm_write(ctrl.fd,
+ ctrl.last_command,
+ strlen(ctrl.last_command),
FtpStateData::ftpWriteCommandCallback,
- ftpState);
+ this);
- ftpState->scheduleReadControlReply(0);
+ scheduleReadControlReply(0);
}
void
else
snprintf(cbuf, 1024, "USER %s\r\n", ftpState->user);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_USER;
}
ftpSendPass(FtpStateData * ftpState)
{
snprintf(cbuf, 1024, "PASS %s\r\n", ftpState->password);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_PASS;
}
snprintf(cbuf, 1024, "TYPE %c\r\n", mode);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_TYPE;
}
snprintf(cbuf, 1024, "CWD %s\r\n", path);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_CWD;
}
char *path = ftpState->filepath;
debug(9, 3) ("ftpSendMkdir: with path=%s\n", path);
snprintf(cbuf, 1024, "MKD %s\r\n", path);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_MKDIR;
}
{
assert(*ftpState->filepath != '\0');
snprintf(cbuf, 1024, "MDTM %s\r\n", ftpState->filepath);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_MDTM;
}
assert(ftpState->filepath != NULL);
assert(*ftpState->filepath != '\0');
snprintf(cbuf, 1024, "SIZE %s\r\n", ftpState->filepath);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_SIZE;
} else
/* Skip to next state no non-binary transfers */
snprintf(cbuf, 1024, "PASV\r\n");
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_PASV;
snprintf(cbuf, 1024, "PORT %d,%d,%d,%d,%d,%d\r\n",
addrptr[0], addrptr[1], addrptr[2], addrptr[3],
portptr[0], portptr[1]);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_PORT;
}
if (ftpState->filepath != NULL) {
/* Plain file upload */
snprintf(cbuf, 1024, "STOR %s\r\n", ftpState->filepath);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_STOR;
} else if (httpHeaderGetInt(&ftpState->request->header, HDR_CONTENT_LENGTH) > 0) {
/* File upload without a filename. use STOU to generate one */
snprintf(cbuf, 1024, "STOU\r\n");
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_STOR;
} else {
/* No file to transfer. Only create directories if needed */
ftpSendRest(FtpStateData * ftpState)
{
snprintf(cbuf, 1024, "REST %d\r\n", ftpState->restart_offset);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_REST;
}
snprintf(cbuf, 1024, "LIST\r\n");
}
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_LIST;
}
snprintf(cbuf, 1024, "NLST\r\n");
}
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_NLST;
}
{
assert(ftpState->filepath != NULL);
snprintf(cbuf, 1024, "RETR %s\r\n", ftpState->filepath);
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_RETR;
}
{
assert(ftpState->ctrl.fd > -1);
snprintf(cbuf, 1024, "QUIT\r\n");
- ftpWriteCommand(cbuf, ftpState);
+ ftpState->writeCommand(cbuf);
ftpState->state = SENT_QUIT;
}