柔柔弱弱若若若若若热

33呜呜呜呜呜呜呜呜无无无无鞍山市所所所所所所所所所所所所所人受伤
阅读更多

ftp client若若一问!(在线给分)

11-15

以下是一个简单的试验。通过socket 连接ftp server的21端口。然后USER anonymous , PASS adfo@eea.net试图登陆服务器(支持匿名登陆,用telent server 21,然后送出USER anonymous , PASS adfo@eea.net。可以得到希望的结果)rn////////////////////////////////////rn////rn#include rn#include rn#include rn#include rn#include rn#include rn#include rn#include rnrnrn#define PORT 21rn//struct ioctl_data_t d;rnrnrnint main(int argc, char *argv[])rnrn int socketfd , numreceive;rn struct hostent* server;rn struct sockaddr_in server_addr;rn char buffer[5000];rn char hostname[] = "real.nwu.edu.cn";rnrn if ((server = gethostbyname(hostname)) == NULL) //DNSrn printf("Get Host error\n");rn exit(-1);rn rnrn if ((socketfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) //initlization socketrn printf("socket initliaztion error\n");rn exit(-1);rn rn server_addr.sin_family = AF_INET;rn server_addr.sin_port = htons(PORT);rn server_addr.sin_addr = *((struct in_addr*)server->h_addr);rn bzero(&(server_addr.sin_zero) , 8);rnrn if (connect(socketfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) //connect;rn printf("connect error\n");rn exit(-1);rn rnrn int i = 1;rn while(i!=2)rn if ((numreceive = recv(socketfd, buffer, sizeof(buffer), 0)) == -1) //receive message from a socketrn printf("receive message error\n");rn exit(-1);rn rn i++;rn rnrn int buffer_end = sizeof(buffer) + 1;rn buffer[buffer_end] = '\0';rn printf("%s" , buffer);rnrn char send_msg[] = "USER anonymous\n"; //send anonymous quest and receive server message;rn rn if ((numreceive = send(socketfd, send_msg, sizeof(send_msg), 0)) == -1)rn printf ("send message error\n");rn exit(-1);rn rn if ((numreceive = recv(socketfd, buffer, sizeof(buffer), 0)) == -1) //receive message from a socketrn printf("receive message error\n");rn exit(-1);rn rn rn buffer[numreceive + 1] = '\0';rn printf("%s\n", buffer);rnrn char send_msg2[] = "PASS adfoa@245.net\n"; //send password and receive message from serverrn rn if ((numreceive = send(socketfd, send_msg2, sizeof(send_msg2), 0)) == -1)rn printf ("send message error\n");rn exit(-1);rn rnrn if ((numreceive = recv(socketfd, buffer, sizeof(buffer), 0)) == -1) //receive message from a socketrn printf("receive message error\n");rn exit(-1);rn rnrn buffer[numreceive + 1] = '\0';rn printf("%s\n" , buffer);rn close(socketfd);rn return 0;rnrn//////////////////////////rn运行后的提示如下:(faint.........)rn///rn220 real FTP server (Version wu-2.6.1(1) Wed Aug 9 05:54:50 EDT 2000) ready.rn331 Guest login ok, send your complete e-mail address as password.rn)rn530 Please login with USER and PASS.rnrn问题好像出在PASS *******那块。在SEND passwd时。是否需要加密(md5?)。可是我看了一些ftp client 的源码好像都不用。而且就算要加密。server也应当send一个rnencrypt key 过来。rn难道要用ioctl来转换么?没用过这个函数。有谁能说说。rn

ftp client若若的一问(在线给分)

11-15

以下是一个简单的试验。通过socket 连接ftp server的21端口。然后USER anonymous , PASS adfo@eea.net试图登陆服务器(支持匿名登陆,用telent server 21,然后送出USER anonymous , PASS adfo@eea.net。可以得到希望的结果)rn////////////////////////////////////rn////rn#include rn#include rn#include rn#include rn#include rn#include rn#include rn#include rnrnrn#define PORT 21rn//struct ioctl_data_t d;rnrnrnint main(int argc, char *argv[])rnrn int socketfd , numreceive;rn struct hostent* server;rn struct sockaddr_in server_addr;rn char buffer[5000];rn char hostname[] = "real.nwu.edu.cn";rnrn if ((server = gethostbyname(hostname)) == NULL) //DNSrn printf("Get Host error\n");rn exit(-1);rn rnrn if ((socketfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) //initlization socketrn printf("socket initliaztion error\n");rn exit(-1);rn rn server_addr.sin_family = AF_INET;rn server_addr.sin_port = htons(PORT);rn server_addr.sin_addr = *((struct in_addr*)server->h_addr);rn bzero(&(server_addr.sin_zero) , 8);rnrn if (connect(socketfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) //connect;rn printf("connect error\n");rn exit(-1);rn rnrn int i = 1;rn while(i!=2)rn if ((numreceive = recv(socketfd, buffer, sizeof(buffer), 0)) == -1) //receive message from a socketrn printf("receive message error\n");rn exit(-1);rn rn i++;rn rnrn int buffer_end = sizeof(buffer) + 1;rn buffer[buffer_end] = '\0';rn printf("%s" , buffer);rnrn char send_msg[] = "USER anonymous\n"; //send anonymous quest and receive server message;rn rn if ((numreceive = send(socketfd, send_msg, sizeof(send_msg), 0)) == -1)rn printf ("send message error\n");rn exit(-1);rn rn if ((numreceive = recv(socketfd, buffer, sizeof(buffer), 0)) == -1) //receive message from a socketrn printf("receive message error\n");rn exit(-1);rn rn rn buffer[numreceive + 1] = '\0';rn printf("%s\n", buffer);rnrn char send_msg2[] = "PASS adfoa@245.net\n"; //send password and receive message from serverrn rn if ((numreceive = send(socketfd, send_msg2, sizeof(send_msg2), 0)) == -1)rn printf ("send message error\n");rn exit(-1);rn rnrn if ((numreceive = recv(socketfd, buffer, sizeof(buffer), 0)) == -1) //receive message from a socketrn printf("receive message error\n");rn exit(-1);rn rnrn buffer[numreceive + 1] = '\0';rn printf("%s\n" , buffer);rn close(socketfd);rn return 0;rnrn//////////////////////////rn运行后的提示如下:(faint.........)rn///rn220 real FTP server (Version wu-2.6.1(1) Wed Aug 9 05:54:50 EDT 2000) ready.rn331 Guest login ok, send your complete e-mail address as password.rn)rn530 Please login with USER and PASS.rnrn问题好像出在PASS *******那块。在SEND passwd时。是否需要加密(md5?)。可是我看了一些ftp client 的源码好像都不用。而且就算要加密。server也应当send一个rnencrypt key 过来。rn难道要用ioctl来转换么?没用过这个函数。有谁能说说。

没有更多推荐了,返回首页