OnFinalRelease()对此函数调用出错,错误日志见帖子:

zhaolixin007 2011-02-25 10:26:29
错误日志:
error C2352: 'CWnd::OnFinalRelease' : illegal call of non-static member function
void OnFinalRelease()
{
CDialog::OnFinalRelease();
}
...全文
335 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaolixin007 2011-03-15
  • 打赏
  • 举报
回复
FTP 服务器:

CFtpServer::CFtpServer()
{

}

CFtpServer::~CFtpServer()
{

}

BOOL CFtpServer::Start()
{
if(!Load())
{
cout << "" << endl;
return FALSE;
}
if(!m_sock.Create(21))
{
cout << "ftp socket create error!" << endl;
return FALSE;
}
m_sock.Listen();
CSocket32* pSock = new CSocket32;
while(m_sock.Accept(*pSock))
{
string str = "220 Welcome lqm_ftp";
str += CRLF;
pSock ->Send(str.c_str(),str.size());
OnReceive(pSock);
pSock = new CSocket32;
}
return TRUE;
}

BOOL CFtpServer::Process(CSocket32 *pSock,const string& szCmd,const string& szData)
{
if(szCmd == "USER")
return USER(pSock,szData);
if(szCmd == "PASS")
return PASS(pSock,szData);


return FALSE;
}

void CFtpServer::OnReceive(CSocket32 *pSock)
{
char s[2000];
int nRet = 0;
while((nRet = pSock ->Receive(s,sizeof(s))) > 0)
{
s[nRet] = 0;
string str = s;
int i = str.find(' ');
string szCmd = str.substr(0,i);
string szData = str.substr(i+1,str.size()-3-i);
if(!Process(pSock,szCmd,szData))
break;

}
delete pSock;
}

BOOL CFtpServer::USER(CSocket32 *pSock, const string &szData)
{
string str;
if(!m_map.count(szData))
{
str = "530 User not found!";
str += CRLF;
pSock ->Send(str.c_str(),str.size());
return FALSE;
}
str = "331 Please Pass word";
str += CRLF;
pSock ->Send(str.c_str(),str.size());
return TRUE;
}

BOOL CFtpServer::Load()
{//文件
m_map["test"] = "test";
return TRUE;
}
zhaolixin007 2011-03-15
  • 打赏
  • 举报
回复
FTP 客户端程序
#include <iostream>
#include <String.h>
#include <winsock2.h>
#include <fstream>
#include <string>

void open(char *serverIP);//连接服务器
void name(char *name);//发送用户名
void password(char *password);//发送密码
void input(char *input);//分离输入的命令和参数
void close();//关闭连接
void ls(char *CmdInput);//显示文件列表
void port(SOCKET *listenSock);//设置端口
void dele(char *filename);//删除文件
void retr(char *filename);//下载文件
void stor(char *filename);//上传文件

WSADATA wsaData;
SOCKET cmdsocket;
char CmdInput[100];
char *Command;
char *Parameter;

void main()
{

cout<<"CYftp>";
input(CmdInput);

if(strcmp(Command,"open")==0)//比较命令,连接服务器
{

open(Parameter);//连接服务器

cout<<"username:";//输入用户名
cin>>CmdInput;
name(CmdInput);//发送用户名

cout<<"password:";//输入密码
cin>>CmdInput;
password(CmdInput);//发送密码
cin.get();
cout<<"ftp>";
input(CmdInput);
}
if(strcmp(Command,"close")==0)//比较命令,调用关闭函数
{
close();
}
if(strcmp(Command,"ls")==0)//比较命令,调用显示文件列表函数
{
ls(CmdInput);
cin.get();
cout<<"ftp>";
input(CmdInput);
dele(Parameter);
}
if(strcmp(Command,"dele")==0)//比较命令,调用删除文件函数
{
dele(Parameter);
ls("ls");
cin.get();
cout<<"ftp>";
input(CmdInput);
}
if(strcmp(Command,"retr")==0)//比较命令,调用下载文件文件函数
{
retr(Parameter);
cin.get();
cout<<"ftp>";
input(CmdInput);
}
if(strcmp(Command,"stor")==0)//比较命令,调用上传文件文件函数
{
stor(Parameter);
ls("ls");
cin.get();
cout<<"ftp>";
input(CmdInput);
}

}

//分离输入的命令和参数
void input(char *input)
{
cin.get(input,100);
Command = strtok(CmdInput," ");
Parameter= strtok(NULL, " " );
}

//连接服务器
void open(char *serverIP)
{
char buf[4096];
int retCode;

if(WSAStartup(MAKEWORD(2,2),&wsaData)!=0)
{
cout<<"socket init error"<<endl;
}
cmdsocket=socket(AF_INET,SOCK_STREAM,0);
sockaddr_in serveraddr;
serveraddr.sin_addr.s_addr=inet_addr(serverIP);
serveraddr.sin_family=AF_INET;
serveraddr.sin_port=htons(21);
if(connect(cmdsocket,(const sockaddr *)&serveraddr,sizeof(sockaddr))==SOCKET_ERROR)
{
cout<<"connect error!";
closesocket(cmdsocket);
}

retCode=recv(cmdsocket,buf,4096,0);
buf[retCode]='\0';
cout<<buf;
}

//发送用户名
void name(char *name)
{

char buf[4096];
int retCode;

strcpy(buf,"USER ");
strcat(buf,name);
strcat(buf,"\r\n");
send(cmdsocket,buf,strlen(buf),0);
retCode=recv(cmdsocket,buf,4096,0);
if(retCode==SOCKET_ERROR||retCode==0)
{
cout<<"Error!";
}

buf[retCode]='\0';
cout<<buf;
}

//发送密码
void password(char *password)
{
char buf[4096];
int retCode;

strcpy(buf,"PASS ");
strcat(buf,password);
strcat(buf,"\r\n");
send(cmdsocket,buf,strlen(buf),0);
retCode=recv(cmdsocket,buf,4096,0);
if(retCode==SOCKET_ERROR||retCode==0)
{
cout<<"Error!";
}

buf[retCode]='\0';
cout<<buf;
}

//关闭服务器
void close()
{
char buf[4096];
int retCode;

strcpy(buf,"QUIT\r\n");
send(cmdsocket,buf,strlen(buf),0);
retCode=recv(cmdsocket,buf,4096,0);
if(retCode==SOCKET_ERROR||retCode==0)
{
cout<<"Error!";
}

buf[retCode]='\0';
cout<<buf;
}

//显示文件列表
void ls(char *CmdInput)
{
SOCKET listensocket;
SOCKET clientsocket;
sockaddr_in clientaddr;
int sizeaddr=sizeof(sockaddr);
std::string str;
ofstream file;

char buf[4096];
int retCode;

port(&listensocket);

strcpy(buf,"LIST\r\n");
retCode=send(cmdsocket,buf,strlen(buf),0);
retCode=recv(cmdsocket,buf,4096,0);
if(retCode==SOCKET_ERROR||retCode==0)
{
cout<<"Error!";
}
buf[retCode]='\0';
cout<<buf;
clientsocket=accept(listensocket,(struct sockaddr*)&clientaddr,&sizeaddr);
closesocket(listensocket);
str=std::string(".")+"//"+"list.txt";
file.open(str.c_str(),ios::binary);
retCode=recv(clientsocket,buf,4096,0);
file.write(buf,retCode);
buf[retCode]='\0';
cout<<buf;
file.close();
closesocket(clientsocket);
}

//设置端口
void port(SOCKET *listenSock)
{
char buffer[1024];
int retCode;
std::string dip="127.0.0.1";
std::string::size_type pos=0;
sockaddr_in localAddr;
int sizeAddr=sizeof(sockaddr);
UINT dataport;
std::string str;
*listenSock=socket(AF_INET,SOCK_STREAM,0);
localAddr.sin_addr.s_addr=inet_addr("127.0.0.1");
localAddr.sin_family=AF_INET;
localAddr.sin_port=htons(0);
if(bind(*listenSock,(const sockaddr*)& localAddr,sizeAddr)==SOCKET_ERROR)
{
cout<<"监听失败 "<<GetLastError()<<endl;
}
listen(*listenSock,5);
getsockname(*listenSock,(struct sockaddr*)&localAddr,&sizeAddr);
dataport=ntohs(localAddr.sin_port);
while((pos=dip.find(".", pos))!=std::string::npos)
dip.replace(pos,1, ",");
sprintf(buffer,"PORT %s,%d,%d\r\n",dip.c_str(),dataport/256,dataport%256);
retCode=send(cmdsocket,buffer,strlen(buffer),0);
buffer[retCode]='\0';
cout<<buffer;
}

//删除文件
void dele(char *filename)
{
char buf[4096];
int retCode;

strcpy(buf,"DELE ");
strcat(buf,filename);
strcat(buf,"\r\n");

send(cmdsocket,buf,strlen(buf),0);
retCode=recv(cmdsocket,buf,4096,0);
if(retCode==SOCKET_ERROR||retCode==0)
{
cout<<"Error!";
}

buf[retCode]='\0';
cout<<buf;
}

//下载文件
void retr(char *filename)
{
SOCKET listensocket;
SOCKET clientsocket;
sockaddr_in clientaddr;
int sizeaddr=sizeof(sockaddr);
std::string str;
ofstream file;

char buf[4096];
int retCode;

port(&listensocket);

strcpy(buf,"RETR ");
strcat(buf,filename);
strcat(buf,"\r\n");

retCode=send(cmdsocket,buf,strlen(buf),0);
retCode=recv(cmdsocket,buf,4096,0);
if(retCode==SOCKET_ERROR||retCode==0)
{
cout<<"Error!";
}
buf[retCode]='\0';
cout<<buf;
clientsocket=accept(listensocket,(struct sockaddr*)&clientaddr,&sizeaddr);
closesocket(listensocket);
str=std::string(".")+"//"+filename;
file.open(str.c_str(),ios::binary);
retCode=recv(clientsocket,buf,4096,0);
file.write(buf,retCode);
file.close();
closesocket(clientsocket);
}

//上传文件
void stor(char *filename)
{
SOCKET listensocket;
SOCKET clientsocket;
sockaddr_in clientaddr;
int sizeaddr=sizeof(sockaddr);
std::string str;
ifstream file;
filebuf *fb;
int length;
int left;


char buf[4096];
int retCode;

port(&listensocket);

strcpy(buf,"STOR ");
strcat(buf,filename);
strcat(buf,"\r\n");

retCode=send(cmdsocket,buf,strlen(buf),0);
retCode=recv(cmdsocket,buf,4096,0);
if(retCode==SOCKET_ERROR||retCode==0)
{
cout<<"Error!";
}
buf[retCode]='\0';
cout<<buf;
clientsocket=accept(listensocket,(struct sockaddr*)&clientaddr,&sizeaddr);
closesocket(listensocket);
str=std::string(".")+"//"+filename;
file.open(str.c_str(),ios::binary);
fb=file.rdbuf();
length=fb->seekoff(0,ios::end,ios::in)-fb->seekoff(0,ios::beg,ios::in);
left=length;
while(left>0)
{
file.read(buf,4096<left?4096:left);
send(clientsocket,buf,4096<left?4096:left,0);
left-=4096;
cout<<".";
}
cout<<endl;
file.close();
closesocket(clientsocket);
}
zgl7903 2011-03-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 zhaolixin007 的回复:]
错误日志:
error C2352: 'CWnd::OnFinalRelease' : illegal call of non-static member function
void OnFinalRelease()
{
CDialog::OnFinalRelease();
}
[/Quote]

void CxxxClass::OnFinalRelease()
{
CDialog::OnFinalRelease();
}

zhaolixin007 2011-03-14
  • 打赏
  • 举报
回复
227 Entering passive mode.
230 User logged in; proceed.
331 User name okay; need password.
332 Need account for login.
350 Requested file action pending further information.
450 Requested file action not taken: file unavailable (for example, file busy).
421 Service not available, closing Telnet connection. This can be a reply to any command if the service must shut down.
425 Cannot open data connection.
426 Connection closed; transfer aborted.
530 Not logged in.
532 Need account for storing files.
550 Requested action not taken.

五、 参阅函数:
1、 _mkdir
2、 _rmdir
3、 _remove
4、 _rename
5、 _findfirst
6、 _findnext
7、 _findclose
8、

六、 FTP Commands
! Runs the specified command on the local computer.
? Displays descriptions for ftp commands. Identical to help.
append Appends a local file to a file on the remote computer, using the current file type setting.
ascii Sets the file transfer type to ASCII, the default.
bell Toggles a bell to ring after each file transfer command is completed. By default, the bell is off.
binary Sets the file transfer type to binary.
bye Ends the FTP session with the remote computer and exits ftp.
cd Changes the working directory on the remote computer.
close Ends the FTP session with the remote server and returns to the command interpreter.
debug Toggles debugging. When debugging is on, each command sent to the remote computer is printed, preceded by the string --->. By default, debugging is off.
delete Deletes files on remote computers.
dir Displays a list of a remote directory’s files and subdirectories.
disconnect Disconnects from the remote computer, retaining the ftp prompt.
get Copies a remote file to the local computer, using the current file transfer type. Identical to recv.
glob Toggles file name globbing. Globbing permits use of wildcard characters in local file or path names. By default, globbing is on.
hash Toggles hash-mark (#) printing for each 2048 bytes data block transferred. By default, hash-mark printing is off.
help Displays descriptions for FTP commands.
lcd Changes the working directory on the local computer. By default, the current directory on the local computer is used.
literal Sends arguments, verbatim, to the remote FTP server. A single FTP reply code is expected in return. Identical to quote.
ls Displays an abbreviated list of a remote directory’s files and subdirectories.
mdelete Deletes multiple files on remote computers.
mdir Displays a list of a remote directory’s files and subdirectories. Allows you to specify multiple files.
mget Copies multiple remote files to the local computer using the current file transfer type.
mkdir Creates a remote directory.
mls Displays an abbreviated list of a remote directory’s files and subdirectories.
mput Copies multiple local files to the remote computer, using the current file transfer type.
open Connects to the specified FTP server.
prompt Toggles prompting. During multiple file transfers, ftp provides prompts to allow you to selectively retrieve or store files; mget and mput transfer all files if prompting is turned off. By default, prompting is on.
put Copies a local file to the remote computer, using the current file transfer type. Identical to send.
pwd Prints the current directory on the remote computer.
quit Ends the FTP session with the remote computer and exits ftp.
quote Sends arguments, verbatim, to the remote FTP server. A single FTP reply code is expected in return. Identical to literal.
recv Copies a remote file to the local computer, using the current file transfer type. Identical to get.
remotehelp Displays help for remote commands.
rename Renames remote files.
rmdir Deletes a remote directory.
send Copies a local file to the remote computer, using the current file transfer type. Identical to put.
status Displays the current status of FTP connections and toggles.
trace Toggles packet tracing; displays the route of each packet when running an FTP command.
type Sets or displays the file transfer type.
user Specifies a user to the remote computer.
verbose Toggles verbose mode. If on, all FTP responses are displayed; when a file transfer completes, statistics regarding the efficiency of the transfer are also displayed. By default, verbose is on.
zhaolixin007 2011-03-14
  • 打赏
  • 举报
回复
ftp可以浏览有2种传输格式,文本[A]和二进制格式[I]。
变更或保存对方要求的格式。[等到开始传输时以其中一种格式打开文件]
发送:200协议,格式类型已设置好。

10、 PASV:正向连接模式
创建另个侦听端口:用于接受对方connect,浏览文件信息端口。判断创建侦听端口成功。
成功:发送227协议,例如:Entering Passive Mode (192,168,1,13,4,41)
失败:发送425协议,创建失败。
格式:5个“,”分别代表IP4个段,端口2个段:高位,低位。
Accept产生一个收发端口(pasvSocket),等待发送文件信息。
11、 LIST:
列出文件信息。
发送前:发送150协议,准备开始发送。
发送后:发送226协议,文件信息发送成功。
中间:由pasvSocket连续该目录下所有文件的信息发送,之后关闭pasvSocket。
格式:目录是d,文件是-
Send18=drwxrwxrwx 1 test nogroup 0 Aug 30 02:47 .
Send19=drwxrwxrwx 1 test nogroup 0 Aug 30 02:47 ..
Send20=-rwxrwxrwx 1 test nogroup 9 Aug 30 02:48 Test.txt

12、 NOOP:进入命令模式
发送200协议,Command okay。
13、 DELE:删除文件。
成功:250,失败:553
14、 RNFR:重命名文件开始。
记录OldName后,发送350,Requested new file name。
15、 RNTO:重命名结束:
成功:250,失败:553
16、 MKD:新建文件夹
成功:250,失败:553
17、 RMD:删除文件夹
成功:250,失败:553
18、 STOR:上传文件,
参数:文件名或(带相对路径的文件名)
根据TYPE(I或A)采用2进制或者文本模式,打开绝对路径的文件。
打开成功,使用协议通道(socka)发送150协议,失败发送426返回。
使用数据传输通道(sockt)循环接收数据,并根据接收返回值长度写入文件。
完成后关闭文件,使用协议通道发送226协议。
19、 RETR下载文件
参数:文件名或(带相对路径的文件名)
根据TYPE(I或A)采用2进制或者文本模式,打开绝对路径的文件。
打开成功,使用协议通道(socka)发送150协议,失败发送426返回。
循环读取文件,使用数据传输通道(sockt)根据读取返回值发送读取的数据
完成后关闭文件,使用协议通道发送226协议。

20、 SIZE:获取要下载文件的长度。
参数:文件名或(带相对路径的文件名)
获取按绝对路径的文件,如果文件存在发送213协议,后跟长度数字[描述]。
如果文件不存在也发送213协议,后跟0数字[描述]。
21、 PORT:反连接模式,跟PASV相反的模式
参数:IP和PORT
使用sockt创建0端口,并连接参数中的IP和PORT。
连接成功:发送200协议。 PORT command successful.
连接失败:发送425协议。 Cannot open data connection.
四、 参考资料:
Table 1.10 FTP Server Return Codes
Code Meaning
119 Terminal not available, will try mailbox.
120 Service ready in nnn minutes.
125 Data connection already open; transfer starting.
225 Data connection open; no transfer in progress.
150 File status okay; about to open data connection.
151 User not local; will forward to user@host.
152 User unknown; mail will be forwarded by the operator.
250 Requested file action okay, completed.
200 Command okay.
211 System status, or system help reply.
212 Directory status.
213 File status.
214 Help message.
220 Service ready for new user.
221 Service closing Telnet connection.
226 Closing data connection; requested file action successful (for example, file transfer or file abort).
zhaolixin007 2011-03-14
  • 打赏
  • 举报
回复
二、 连接协议:
所有ftp协议没有2进制数字,全部用文本格式收发。
发送协议:协议号+描述+CRLF
接收协议:协议键+描述+CRLF
其中,协议号和协议键是关键字,不能随意变换。
#define CRLF “\r\n”
CRLF作为校验使用,因此是必须出现在发送或者接收字串的结尾。
发送长度必须等于strlen或者string.length。发送长度也是校验条件之一。
协议键不区分大小写给以处理。
例如:创建ftp端口21,使用IE浏览器执行登录。
收到Accept连接后立即返回Send1,之后使用Receive接收你将收到Recv2。
依次向下收发,得到的测试结果如下:
Send1=220 127.0.0.1 FtpD for free
Recv2=USER test
Send3=331 Password required for test .
Recv4=PASS test
Send5=230 User test logged in , proceed
Recv6=opts utf8 on
Send7=502 Command OPTS utf8 on not implemented
Recv8=syst
Send9=215 Windows
Recv10=site help

Send11=502 Command SITE help not implemented
Recv12=PWD
Send13=257 "/" is current directory
Recv14=CWD /subing/
Send15=250 "/subing/" is current directory.
Recv16=TYPE A
Send17=200 Type set to ASCII.
Recv18=PASV
Send19=425 Cannot open data connection (192.168.1.13 0 create failed)
Recv20=TYPE A
Send21=200 Type set to ASCII.
Recv22=PORT 127,0,0,1,4,226
Send23=200 Port command okay.
Recv24=LIST
Send25=150 Opening ASCII NO-PRINT mode data connection for ls -l.
三、 协议内容:
每一个协议都是一个判断分支语句,得到是或否的结果再返回(发送)。

1、 Accept:
收到连接请求,根据对方的IP判断是否允许访问。
是:发送220协议,相关描述自定义。
否:关闭Accept产生的收发套接字(socka)。[关闭前也可以发送一条错误信息描述]
2、 USER:
判断描述字符串是否在用户列表中。
是:发送331协议,接续校对密码。
否:发送530协议,登录失败,关闭收发套接字。
3、 PASS:
根据上次收到的USER到用户列表<map>中去超找密码,判断和当前收到的PASS是否一致。
是:发送230协议。
否:发送530协议,登陆失败,关闭收发套接字。
其他协议,在没有完成登录的情况下收到,都不予以处理,返回530错误关闭套接字。
4、 Opts:
5、 Syst:
判断服务器的操作系统环境,返回215协议。
6、 Site:
7、 PWD:
判断FTP根目录是否存在。(例如:D:\FTP\.)
是:发送250协议,根目录可以使用。
否:发送503协议,根目录不能访问。
8、 CWD:
变更当前目录(Change Work Directory)。判断“根目录+子目录”是否存在。
是:发送250协议,当前目录已改变。
否:发送550协议,该目录无法访问。
9、 TYPE:
真相重于对错 2011-02-25
  • 打赏
  • 举报
回复
你不能这么调用 onfinalrelease 不是cdialog的静态函数不能直接调用

ouyh12345 2011-02-25
  • 打赏
  • 举报
回复
基类弄错了吧

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧