xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 35KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-05-13
  • 語(yǔ)言: 其他
  • 標(biāo)簽: Linux??

資源簡(jiǎn)介

Linux下的ftp實(shí)現(xiàn)方法,可以連接遠(yuǎn)程服務(wù)器,實(shí)現(xiàn)下載上傳

資源截圖

代碼片段和文件信息

#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
//記錄端口號(hào)IP地址
struct?sockaddr_in?ftp_server?local_host;//FTP服務(wù)器?本地主機(jī)

//該結(jié)構(gòu)記錄主機(jī)的信息,包括主機(jī)名、別名、地址類型、地址長(zhǎng)度和地址列表。
struct?hostent?*?server_hostent;//該結(jié)構(gòu)記錄主機(jī)的信息

int?sock_control;

//ftp?mode?0?is?PORT(主動(dòng)模式)?1?is?PASV(被動(dòng)模式);
int?mode?=?1;?

//echo_off?and?echo_on?for?get?usr?password?from?stdin
//echo_off和echo_on從標(biāo)準(zhǔn)輸入獲得用戶名和密碼。
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;
}
//命令錯(cuò)誤退出
void?cmd_err_exit(char?*?err_msg?int?err_code)
{
printf(“%s\n“?err_msg);
exit(err_code);
}
/*************************************************/
//函數(shù)功能:向結(jié)構(gòu)體中添加IP地址與端口號(hào)
//函數(shù)參數(shù):IP地址,結(jié)構(gòu)體,端口號(hào)

/*************************************************/
int?fill_host_addr(char?*?host_ip_addr?struct?sockaddr_in?*?host?int?port)
{
//如果端口號(hào)小于或等于0??或者大于65535
if(port?<=?0?||?port?>?65535)?
return?254;
//將結(jié)構(gòu)體清零
bzero(host?sizeof(struct?sockaddr_in));
//設(shè)置為?IPv4?網(wǎng)絡(luò)協(xié)議的套接字類型
host->sin_family?=?AF_INET;
//如果正確執(zhí)行將返回一個(gè)無(wú)符號(hào)長(zhǎng)整數(shù)型數(shù)。
//如果傳入的字符串不是一個(gè)合法的IP地址,將返回INADDR_NONE。
????if(inet_addr(host_ip_addr)?!=?-1)
{
//將地址保存到結(jié)構(gòu)體中
????????host->sin_addr.s_addr?=?inet_addr(host_ip_addr);
}
????else?
{
//返回對(duì)應(yīng)于給定主機(jī)名的包含主機(jī)名字和地址信息的hostent結(jié)構(gòu)的指針。
if((server_hostent?=?gethostbyname(host_ip_addr))?!=?0)
{
//將地址放在結(jié)構(gòu)體中
memcpy(&host->sin_addr?server_hostent->h_addr\
????????sizeof(host->sin_addr));
}
????????else?return?253;
}
//將端口號(hào)保存在結(jié)構(gòu)體中
????host->sin_port?=?htons(port);
return?1;
}


/*************************************************/
//函數(shù)功能:創(chuàng)建socket并連接,設(shè)置收發(fā)時(shí)間,
//函數(shù)參數(shù):IP地址端口號(hào)結(jié)構(gòu)體,收發(fā)時(shí)間設(shè)置(1?!1?3秒)
//?返回值?:配置好的Socket
/*************************************************/
int?xconnect(struct?sockaddr_in?*s_addr?int?type)
{
struct?timeval?outtime;
int?set;
//SOCK_STREAM:?提供面向連接的穩(wěn)定數(shù)據(jù)傳輸,即TCP協(xié)議。
//創(chuàng)建scoket
int?s?=?socket(AF_INET?SOCK_STREAM?0);
if(s? cmd_err_exit(“creat?socket?error!“?249);
//為控制設(shè)定時(shí)間?socket
//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;
}
//設(shè)置socket收發(fā)時(shí)限。
set?=?setsockopt(s?SOL_SOCKETSO_RCVTIMEO?&outtimesizeof(outtime));
if(set?!=0)
{
//失敗輸出錯(cuò)誤原因。
printf

評(píng)論

共有 條評(píng)論