Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions CFtpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ int CFtpHandler::getDataSocket() {
bool CFtpHandler::handleRequest(char *buff) {
stringstream recvStream;
recvStream<<buff;

cout<<buff;
string command;
recvStream>>command;


/* allow client input lowercast commond */
std::transform(command.begin(), command.end(), command.begin(),::toupper);

bool isClose = false;
string msg;
//username
Expand Down Expand Up @@ -259,7 +262,7 @@ bool CFtpHandler::handleRequest(char *buff) {
struct tm tm = *gmtime(&s.st_mtime);
//list with -l param
if (param == "-l") {
stream<<s.st_mode<<" "<<s.st_nlink<<" "<<s.st_uid<<" "<<s.st_gid<<" "<<setw(10)<<s.st_size<<" "<<tm.tm_mon<<" "<<tm.tm_mday<<" "<<tm.tm_year<<" "<<ent->d_name<<endl;
stream<<s.st_mode<<" "<<s.st_nlink<<" "<<s.st_uid<<" "<<s.st_gid<<" "<<setw(10)<<s.st_size<<" "<<tm.tm_mon+1<<" "<<tm.tm_mday<<" "<<tm.tm_year+1900<<" "<<ent->d_name<<endl;
}else {
stream<<ent->d_name<<endl;
}
Expand All @@ -282,6 +285,7 @@ bool CFtpHandler::handleRequest(char *buff) {
int newFd = getDataSocket();
//send file
std::ifstream file((ROOT_PATH+currentPath+fileName).c_str(),std::ifstream::in);

file.seekg(0, std::ifstream::beg);
while(file.tellg() != -1)
{
Expand Down Expand Up @@ -360,6 +364,9 @@ bool CFtpHandler::handleRequest(char *buff) {
else if (command == COMMAND_NOOP || command == COMMAND_OPTS){
msg = TS_FTP_STATUS_OK;
}
else
msg = TS_FTP_STATUS_CMD_ERROR;


sendResponse(m_connFd, msg);
return isClose;
Expand Down
6 changes: 3 additions & 3 deletions CFtpHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
#ifndef __TSFtpServer__CFtpHandler__
#define __TSFtpServer__CFtpHandler__

#include <algorithm>
#include <iostream>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>

#include <cctype>
#include <cstdio>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>

/**************************************
* FTP Commond List
*************************************/

#define COMMAND_PORT "PORT"
#define COMMAND_PASSIVE "PASV"
#define COMMAND_LIST "LIST"
Expand All @@ -50,7 +50,6 @@
/**************************************
* FTP Response Codes
*************************************/

#define TS_FTP_STATUS_READY "220 TS FTP Server ready...\r\n"

#define TS_FTP_STATUS_OPEN_DATA_CHANNEL "150 Opening data channel for directory list."
Expand All @@ -72,6 +71,7 @@
#define TS_FTP_STATUS_DELETE "250 DELE command successful."
#define TS_FTP_STATUS_CUR_DIR(x) "257 \""+x+"\" is current directory."
#define TS_FTP_STATUS_PWD_REQ(x) "331 Password required for "+x
#define TS_FTP_STATUS_CMD_ERROR "500 Syntax error, command unrecognized."
#define TS_FTP_STATUS_PWD_ERROR "530 Not logged in,password error."
#define TS_FTP_STATUS_FILE_NOT_FOUND "550 File not found"
#define TS_FTP_STATUS_CWD_FAILED(x) "550 CWD command failed. \"" +x+ "\": directory not found."
Expand Down