meimei10251314 发表于 2015-5-29 09:20:37

基于socket的ftp实现(一)

  服务器端的实现:
#include
#include
#include //sockaddr_in等结构的定义
#include //addrinfo等结构的定义
#include
#include
#include
#include
#include
#include
#include
#define TRUE 1
#define LISTEN_PORT 3499
#define dataLen 1024
char currentDirPath;
char currentDirName;
char help[]="get    get a file from server\n\
put    upload a file to server\n\
pwd    display    the current directory of server\n\
dir    display the files in the current directory of server\n\
cd    change the directory of server\n\
?    display the whole command which equals 'help'\n\
quit    return\n";
char *getDirName(char *dirPathName);
void cmd_pwd(int sock);
void cmd_dir(int sock);
void cmd_cd(int sock,char *dirName);
void cmd_cdback(int sock);
void cmd_help(int sock);
void cmd_get(int sock,char*fileName);
void cmd_put(int sock,char *fileName);

int main(int argc,char *argv[])
{
   int sock,sockmsg, length, lengthmsg;
   char client_cmd , cmd_arg;
   struct sockaddr_in server;
   struct sockaddr_in servermsg;
   int datasock, msgsock;   
   pid_t child;

// int datasock;   //data socket
   int rval;
   sock=socket(AF_INET,SOCK_STREAM,0);//创建流式套接字
   sockmsg=socket(AF_INET,SOCK_STREAM,0);
   if (sock
页: [1]
查看完整版本: 基于socket的ftp实现(一)