91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 31KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-26
  • 語言: C/C++
  • 標簽: 留言簿??

資源簡介

在linux上用C實現FTP服務器,可以上傳文件和下載文件。

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?

#define?DEFAULT_FTP_PORT?21

extern?int?h_errno;

char?user[64];?//ftp?usr
char?passwd[64];?//ftp?passwd

//ftp?server?address
struct?sockaddr_in?ftp_server?local_host;
struct?hostent?*?server_hostent;

int?sock_control;

int?mode?=?1;?//ftp?mode?0?is?PORT?1?is?PASV;

//echo_off?and?echo_on?for?get?usr?password?from?stdin
static?struct?termios?stored_settings;
void?echo_off(void)
{
????struct?termios?new_settings;
????tcgetattr(0&stored_settings);
????new_settings?=?stored_settings;
????new_settings.c_lflag?&=?(~ECHO);
????tcsetattr(0TCSANOW&new_settings);
????return;
}
void?echo_on(void)
{
????tcsetattr(0TCSANOW&stored_settings);
????return;
}

void?cmd_err_exit(char?*?err_msg?int?err_code)
{
printf(“%s\n“?err_msg);
exit(err_code);
}

int?fill_host_addr(char?*?host_ip_addr?struct?sockaddr_in?*?host?int?port)
{
if(port?<=?0?||?port?>?65535)?
return?254;
bzero(host?sizeof(struct?sockaddr_in));
host->sin_family?=?AF_INET;
????????if(inet_addr(host_ip_addr)?!=?-1)
{
????????????????host->sin_addr.s_addr?=?inet_addr(host_ip_addr);
}
????????else?
{
if((server_hostent?=?gethostbyname(host_ip_addr))?!=?0)
{
memcpy(&host->sin_addr?server_hostent->h_addr\
????????sizeof(host->sin_addr));
}
????????else?return?253;
}
????????host->sin_port?=?htons(port);
return?1;
}

int?xconnect(struct?sockaddr_in?*s_addr?int?type)
{
struct?timeval?outtime;
int?set;
int?s?=?socket(AF_INET?SOCK_STREAM?0);
if(s? cmd_err_exit(“creat?socket?error!“?249);

//set?outtime?for?the?control?socket
if(type?==?1)
{
outtime.tv_sec?=?0;
outtime.tv_usec?=?300000;
}
else
{
outtime.tv_sec?=?5;
outtime.tv_usec?=?0;
}
set?=?setsockopt(s?SOL_SOCKETSO_RCVTIMEO?&outtimesizeof(outtime));
if(set?!=0)
{
printf(“set?socket?%s?errno:%d\n“strerror(errno)errno);
cmd_err_exit(“set?socket“?1);
}

//connect?to?the?server
if?(connect(s(struct?sockaddr?*)s_addrsizeof(struct?sockaddr_in))? {
printf(“Can‘t?connect?to?server?%s?port?%d\n“\
inet_ntoa(s_addr->sin_addr)ntohs(ftp_server.sin_port));
exit(252);
}
return?s;
}

//send?command?to?server?with?sock_fd
int?ftp_send_cmd(const?char?*s1?const?char?*s2?int?sock_fd)
{
char?send_buf[256];
int?send_err?len;
if(s1)?
{
strcpy(send_bufs1);
if(s2)
{
strcat(send_buf?s2);
strcat(send_buf“\r\n“);
len?=?strlen(send_buf);
send_err?=?send(sock_fd?send_buf?len?0);
}
else?
{
strcat(send_buf“\r\n“);
len?=?strlen(send_buf);
send_err?=?send(sock

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????1151??2009-11-08?02:56??FTP\ftp.h

?????文件??????30383??2009-11-08?06:52??FTP\ftp_cli

?????文件??????27839??2009-11-08?04:31??FTP\ftp_client.c

?????文件??????24762??2009-11-08?04:21??FTP\ftp_server.c

?????文件??????27190??2009-11-08?06:52??FTP\ftp_srv

?????文件????????182??2009-11-08?06:28??FTP\makefile

?????文件????????309??2009-11-29?18:11??FTP\readme.txt

?????目錄??????????0??2012-11-23?17:32??FTP

-----------?---------??----------?-----??----

???????????????111816????????????????????8


評論

共有 條評論

相關資源