コード例 #1
0
ファイル: ftp.cpp プロジェクト: kaifengz/fasmio
bool FtpConnHandler::On_LIST()
{
    if (data_channel_ip_.empty())
        return SendMessage(425, "Use PORT first.");

    std::string path(working_dir_);
    if (*last_cmd_arg_ != '\0')
    {
        if (*last_cmd_arg_ == '/')
            path = last_cmd_arg_;
        else
            path = working_dir_ + "/" + last_cmd_arg_;
        if (!NormalizePath(path))
            return SendMessage(550, "File unavailable.");
        if (!IsDirectory("." + path))
            return SendMessage(550, "Not a directory.");
    }

    if (!OpenDataConnection())
        return SendMessage(425, "Can't open data connection.");
    if (!SendMessage(150, "Here comes the directory listing."))
        return false;

    bool succeed = ListDirectory("." + path, sock_data_);
    CloseDataConnection();

    if (!succeed)
        return SendMessage(451, "Requested action aborted: local error in processing.");

    return SendMessage(226, "Directory send OK.");
}
コード例 #2
0
ファイル: ftp.cpp プロジェクト: kaifengz/fasmio
bool FtpConnHandler::On_RETR()
{
    if (*last_cmd_arg_ == '\0')
        return SendMessage(550, "No file specified.");

    std::string path;
    if (*last_cmd_arg_ == '/')
        path = last_cmd_arg_;
    else
        path = working_dir_ + "/" + last_cmd_arg_;

    if (!NormalizePath(path))
        return SendMessage(550, "File unavailable.");
    if (!IsFile("." + path))
        return SendMessage(550, "Not a file.");

    if (!OpenDataConnection())
        return SendMessage(425, "Can't open data connection.");
    if (!SendMessage(150, "Here comes the file content."))
        return false;

    bool succeed = SendFile("." + path, bin_mode_, sock_data_);
    CloseDataConnection();

    if (!succeed)
        return SendMessage(451, "Requested action aborted: local error in processing.");

    return SendMessage(226, "File send OK.");
}
コード例 #3
0
ファイル: proxy.c プロジェクト: ColumPaget/MetaFTPD
int ProxyHandleFileTransfer(TSession *Session, char *Command, char *Path, int Direction)
{
STREAM *InFile;
int fd, KeepReading;
char *Tempstr=NULL;

Tempstr=MCopyStr(Tempstr,Command," ",Path,"\r\n",NULL);
STREAMWriteLine(Tempstr,Session->ProxySock); 
STREAMFlush(Session->ProxySock);
LogToFile(Settings.LogPath,"PROXY SEND: %s ",Tempstr);
if (! CopyToSock(Session->ProxySock, Session->ClientSock)) return(FALSE);


if (ProxyOpenDataConnection(Session,0)) 
{

	if (OpenDataConnection(Session,0))
	{
		if (Direction==FILE_SEND) SendFileData(Session->Flags & SESSION_ASCII_TRANSFERS,Session->DataConnection->Sock, Session->ProxyDataConnection->Sock,0);
		else
		{
			 SendFileData(Session->Flags & SESSION_ASCII_TRANSFERS,Session->ProxyDataConnection->Sock, Session->DataConnection->Sock,0);
		}
		CloseDataConnection(Session, Session->DataConnection);
  }

  CloseDataConnection(Session, Session->ProxyDataConnection);
  Tempstr=STREAMReadLine(Tempstr,Session->ProxySock);
  STREAMWriteLine(Tempstr,Session->ClientSock);
	STREAMFlush(Session->ClientSock);

  Session->DataConnection=NULL;
  Session->ProxyDataConnection=NULL;
}

/*
//One day will use this instead
LogToFile(Settings.LogPath, "MADE DATA CON");
DataCon->Input=DataCon->Sock;
LogToFile(Settings.LogPath, "ADD LOCAL CON");
DataCon->Output=Session->DataConnection->Sock;
LogToFile(Settings.LogPath, "SET FNAME");
DataCon->FileName=CopyStr(DataCon->FileName,"Proxy");
DataCon->Flags |= DC_RETR;
Session->DataConnection=NULL;
Session->ProxyDataConnection=NULL;
ListAddItem(Session->FileTransfers,DataCon);
*/



DestroyString(Tempstr);

return(TRUE);
}