当前位置: 技术问答>linux和unix
奇怪!!!关于 ftp 服务器的问题
来源: 互联网 发布时间:2016-05-06
本文导语: char *a, *p, *temp; char szCommand[256]; struct sockaddr_in data_addr; int add; char* c; size_t len = sizeof(data_addr); if (-1==getsockname(ftp->CommandChunnel, (struct sockaddr*)&data_addr, &len)) return false; printf("data_addr.sin_port = %dn",da...
char *a, *p, *temp;
char szCommand[256];
struct sockaddr_in data_addr;
int add;
char* c;
size_t len = sizeof(data_addr);
if (-1==getsockname(ftp->CommandChunnel, (struct sockaddr*)&data_addr, &len))
return false;
printf("data_addr.sin_port = %dn",data_addr.sin_port );
temp = inet_ntoa(data_addr.sin_addr);
printf("Ip is:%sn",temp);
data_addr.sin_port = 0;
data_addr.sin_addr.s_addr = htonl(INADDR_ANY);
data_addr.sin_family = AF_INET;
ftp->DataChunnel = FPF_Socket(SOCK_STREAM);
if (ftp->DataChunnel ==INVALID_SOCKET)
{
printf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaan");
return false;
}
if (-1==bind(ftp->DataChunnel, (struct sockaddr*)&data_addr, sizeof(data_addr)))
{
printf("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbn");
return false;
}
if (-1==getsockname(ftp->DataChunnel, (struct sockaddr*)&data_addr, &len))
{
printf("cccccccccccccccccccccccccccccccccccccccccn");
return false;
}
if (!FPF_SockListen(ftp->DataChunnel, 1))
{
printf("ddddddddddddddddddddddddddddddddddn");
return false;
}
printf("data_addr.sin_port = %dn",data_addr.sin_port );
temp = inet_ntoa(data_addr.sin_addr);
printf("Ip is:%sn",temp);
a = (char *)&data_addr.sin_addr;
p = (char *)&data_addr.sin_port;
add=inet_addr(g_sysinfo.hostIP);
c=(char *)&add;
#define UC(b) (((int)b)&0xff)
sprintf(szCommand, "PORT %d,%d,%d,%d,%d,%d",
UC(c[0]), UC(c[1]), UC(c[2]), UC(c[3]), UC(p[0]), UC(p[1]));
//发送命令,得到结果
if (!FPF_FtpSendCommand(ftp, szCommand) || ftp->nReplyCode/100==ERROR)
return false;
}
return true;
}
结果出现
data_addr.sin_port = 51585
Ip is:192.168.21.27
data_addr.sin_port = 51485
Ip is:192.168.21.27
CMD>PORT 134,128,140,33,29,201
Send command 'PORT 134,128,140,33,29,201' success
Receive reply is [500 Illegal PORT command.
]!
不知道什么原因
如果使用被注释掉的内容,则同样不行,结果为
data_addr.sin_port = 52097
Ip is:192.168.21.27
data_addr.sin_port = 52353
Ip is:0.0.0.0 (注意)
CMD>PORT 134,128,140,33,129,204
Send command 'PORT 134,128,140,33,129,204' success
Receive reply is [500 Illegal PORT command.
]!
char szCommand[256];
struct sockaddr_in data_addr;
int add;
char* c;
size_t len = sizeof(data_addr);
if (-1==getsockname(ftp->CommandChunnel, (struct sockaddr*)&data_addr, &len))
return false;
printf("data_addr.sin_port = %dn",data_addr.sin_port );
temp = inet_ntoa(data_addr.sin_addr);
printf("Ip is:%sn",temp);
data_addr.sin_port = 0;
data_addr.sin_addr.s_addr = htonl(INADDR_ANY);
data_addr.sin_family = AF_INET;
ftp->DataChunnel = FPF_Socket(SOCK_STREAM);
if (ftp->DataChunnel ==INVALID_SOCKET)
{
printf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaan");
return false;
}
if (-1==bind(ftp->DataChunnel, (struct sockaddr*)&data_addr, sizeof(data_addr)))
{
printf("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbn");
return false;
}
if (-1==getsockname(ftp->DataChunnel, (struct sockaddr*)&data_addr, &len))
{
printf("cccccccccccccccccccccccccccccccccccccccccn");
return false;
}
if (!FPF_SockListen(ftp->DataChunnel, 1))
{
printf("ddddddddddddddddddddddddddddddddddn");
return false;
}
printf("data_addr.sin_port = %dn",data_addr.sin_port );
temp = inet_ntoa(data_addr.sin_addr);
printf("Ip is:%sn",temp);
a = (char *)&data_addr.sin_addr;
p = (char *)&data_addr.sin_port;
add=inet_addr(g_sysinfo.hostIP);
c=(char *)&add;
#define UC(b) (((int)b)&0xff)
sprintf(szCommand, "PORT %d,%d,%d,%d,%d,%d",
UC(c[0]), UC(c[1]), UC(c[2]), UC(c[3]), UC(p[0]), UC(p[1]));
//发送命令,得到结果
if (!FPF_FtpSendCommand(ftp, szCommand) || ftp->nReplyCode/100==ERROR)
return false;
}
return true;
}
结果出现
data_addr.sin_port = 51585
Ip is:192.168.21.27
data_addr.sin_port = 51485
Ip is:192.168.21.27
CMD>PORT 134,128,140,33,29,201
Send command 'PORT 134,128,140,33,29,201' success
Receive reply is [500 Illegal PORT command.
]!
不知道什么原因
如果使用被注释掉的内容,则同样不行,结果为
data_addr.sin_port = 52097
Ip is:192.168.21.27
data_addr.sin_port = 52353
Ip is:0.0.0.0 (注意)
CMD>PORT 134,128,140,33,129,204
Send command 'PORT 134,128,140,33,129,204' success
Receive reply is [500 Illegal PORT command.
]!
|
貌似代码不全...
|
还是写个脚本方便,直接调用脚本 system("../ftp_file.sh")