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

  • 大小: 11KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-29
  • 語言: C/C++
  • 標簽: Unix??FTP??C語言??

資源簡介

unix 下實現ftp部分功能ls,get,put,cd,pwd等等功能 C語言代碼

資源截圖

代碼片段和文件信息

/*?header?files?*/
#include
#include
#include /*?getservbyname()?gethostbyname()?*/
#include /*?for?definition?of?errno?*/
#include????
#include????
#include????
#include????
#include????
/*?define?macros*/
#define?MAXBUF 1024
#define?STDIN_FILENO 0
#define?STDOUT_FILENO 1

/*?define?FTP?reply?code?*/
#define?USERNAME 220
#define?PASSWORD 331
#define?LOGIN 230
#define?PATHNAME 257
#define?CLOSEDATA 226
#define?ACTIONOK 250
#define?FAIL????????550

/*?DefinE?global?variables?*/
char *host; /*?hostname?or?dotted-decimal?string?*/
char *port;
char *rbuf?*rbuf1; /*?pointer?that?is?malloc‘ed?*/
char *wbuf?*wbuf1; /*?pointer?that?is?malloc‘ed?*/
struct??sockaddr_in servaddr;
char????*rbuf2?*rbuf3;
int ????cliopen(char?*host?char?*port);
void strtosrv(char?*?char?*?char?*);
void cmd_tcp(int?sockfd);
void ftp_list(int?sockfd);
void ftp_get(int?sck?char?*pDownloadFileName_s);
void ftp_put?(int?sck?char?*pUploadFileName_s);
void????ftp_help();


int
main(int?argc?char?*argv[])
{
int fd;
????struct?hostent?*h;
????
if?(0?!=?argc-2)
{
printf(“%s\n““missing?“);
exit(0);
}

host?=?argv[1];
port?=?“21“;

//code?here:?Allocate?the?read?and?write?buffers?before?open().
????rbuf?=?(char?*)malloc(MAXBUF);
????rbuf1?=?(char?*)malloc(MAXBUF);
????wbuf?=?(char?*)malloc(MAXBUF);
????wbuf1?=?(char?*)malloc(MAXBUF);
????rbuf2?=?(char?*)malloc(MAXBUF);
????rbuf3?=?(char?*)malloc(MAXBUF);
????
????fd?=?cliopen(host?port);
???
cmd_tcp(fd);

exit(0);
}


/*?Establish?a?TCP?connection?from?client?to?server?*/
int
cliopen(char?*host?char?*port)
{
??int?sd?rc?i;
??struct?hostent?*h;
??short?port_int?=?atoi(port);
??
??h?=?gethostbyname(host);
??
??servaddr.sin_family?=?AF_INET;
??memcpy((char?*)?&servaddr.sin_addr.s_addr?h->h_addr_list[0]?h->h_length);
??servaddr.sin_port?=?htons(port_int);
??//printf(“Connecting?%s:%d.......“?inet_ntoa(servaddr.sin_addr)?port_int);
?
??
??/*?create?socket?*/
??sd?=?socket(AF_INET?SOCK_STREAM?0);
??
??if(sd<0)?{
????perror(“cannot?open?socket?“);
????exit(1);
??}
????
??/*?connect?to?server?*/
??rc?=?connect(sd?(struct?sockaddr?*)?&servaddr?sizeof(servaddr));
??if(rc<0)?{
????perror(“Cannot?connect?“);
????exit(1);
??}

??return?sd;?
}


/*
???Compute?server‘s?port?by?a?pair?of?integers?and?store?it?in?char?*port
???Get?server‘s?IP?address?and?store?it?in?char?*host
*/
void
strtosrv(char?*str?char?*host?char?*port)
{
????????int i;
????char?*p;
????????char?*ip;
????char?*portNum;

????
????????p?=?(char?*)malloc(300);
?????? ??????????
??? ????sprintf(p“%s“strchr(str‘(‘));
??? ????
??? ?????ip=++p;
??? ????
??? ????
for(i=0;i<4;i++)
{
p=strchr(ip‘‘);
*p=‘.‘;
}
*p=‘\0‘;

sprintf(host“%s“ip);
?

portNum?=?++p;
p?=?strchr(portNum‘‘);
i?=?atoi(portNum)?*?256?+?atoi(++p);
sprintf(portNum“%d“i);
sprintf(port“%s“portNum);

??????????????????????

評論

共有 條評論