没有语法的错误,可是在连接的时候出了问题,不能生成exe运行
我在vc6和7中都试过#include <winsock.h>
#include <stdlib.h>
#include <stdio.h>UINT ReadFTPServerReply(SOCKET hControlChannel);//将服务器对客户的应答字符串中的前3位的3位数字应答码提取出来
UINT GetReplyCode(LPSTR lpszServerReply)
{
UINT nCode;
char c;

c=*(lpszServerReply+3);
*(lpszServerReply+3)='\0';
nCode=atoi((const char *)lpszServerReply);
*(lpszServerReply+3)=c;
return(nCode);

}//建立控制连接
SOCKET ConnectFTPControlSocket(LPSTR lpszHost,short nPort)
{
LPHOSTENT lpHostEnt;
SOCKADDR_IN sockAddr;
int nConnect;
SOCKET hControlSocket=INVALID_SOCKET;
if(!(lpHostEnt=gethostbyname(lpszHost)))
{
printf("Error#%d while resolving address for %s\n",
   WSAGetLastError(),lpszHost);
return(INVALID_SOCKET);
}
if((hControlSocket=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP))==INVALID_SOCKET)
{
printf("Error#%d occurred while creating socket!!!\n",
   WSAGetLastError());
return(INVALID_SOCKET);
}
//定义socket地址
sockAddr.sin_family=AF_INET;
sockAddr.sin_port=nPort;//端口号///////////////////////////////////////////////////
sockAddr.sin_addr=*((LPIN_ADDR)*lpHostEnt->h_addr_list);
//连接socket
if(nConnect=connect(hControlSocket,(LPSOCKADDR)&sockAddr,sizeof(sockAddr)))
{
printf("Error#%d occurred while connecting socket!!!\n");
return(INVALID_SOCKET);
}
if(ReadFTPServerReply(hControlSocket)>=400)/////////////////////////////////////////////////////
return(INVALID_SOCKET);
else
return(hControlSocket);
}//服务器应答的读取
UINT ReadFTPServerReply(SOCKET hControlChannel)
{
int iBytesRead;
char gsServerReplyText[10];
UINT nReplyCode;

recv(hControlChannel,(LPSTR)gsServerReplyText,
sizeof(gsServerReplyText),MSG_OOB);
puts(gsServerReplyText);
nReplyCode=GetReplyCode(gsServerReplyText);
do
{
iBytesRead=recv(hControlChannel,(LPSTR)gsServerReplyText,
sizeof(gsServerReplyText),MSG_OOB);
puts(gsServerReplyText);
}while(iBytesRead>0);
//Extract the reply code from the server reply and return as an integer.
return(nReplyCode);
}//发送命令
UINT SendFTPCommand(SOCKET hControlChannel,LPSTR gszCommandBuffer)
{
if((send(hControlChannel,(LPSTR)gszCommandBuffer,
lstrlen(gszCommandBuffer),MSG_OOB))==SOCKET_ERROR)
{
printf("Error#%d from the send() function!!!\n",WSAGetLastError());
return(999);
}
//Read the server's reply and return the reply code as an integer
return(ReadFTPServerReply(hControlChannel));
}int main()
{
SOCKET a;
a=ConnectFTPControlSocket("10.5.72.69",21);
ReadFTPServerReply(a);
return 0;
}