static void do_nlst(session_t *sess) { if(get_transfer_fd(sess) == 0) return; ftp_reply(sess, FTP_DATACONN, "Here comes the directory listing."); list_common(sess, 0); close(sess->data_fd); sess->data_fd = -1; ftp_reply(sess, FTP_TRANSFEROK, "Directory send OK."); }
static void do_list(session_t *sess) { if(get_transfer_fd(sess) == 0) return; ftp_reply(sess, FTP_DATACONN, "Here comes the directory listing."); //transfer list list_common(sess, 1); //client will still wait the data from server if the fd do not closed close(sess->data_fd); sess->data_fd = -1; ftp_reply(sess, FTP_TRANSFEROK, "Directory send OK."); }
/** *do_nlst - 处理列出目录列表命令,可用windows登录,命令短清单 *@sess:会话结构体 */ void ftpproto::do_nlst(session_t* sess) { //创建数据连接,主动用connect,被动用accept if (get_transfer_fd(sess))//连接失败 { LCWFTPD_LOG(DEBUG,"get_transfer_fd(sess)"); return; } //150响应 ftp_reply(sess,FTP_DATACONN,"Here comes the directory listing."); //传输列表 list_common(sess,0);//0表示短清单 //关闭数据链接套接字,客户端貌似是通过判断套接字关闭从而判断数据是否接收完毕 close(sess->data_fd); sess->data_fd = -1; //226响应 ftp_reply(sess,FTP_TRANSFEROK,"Directory send OK."); }
int main() { // Person ids starts at 1 aid = 1; // A linked list for storing persons list people; new_list(&people, sizeof(person)); FILE *commands = fopen(commands_file, "r"); if(NULL == commands) { fprintf(stderr, "Can't open commands file for reading. Please make sure it exists!\n"); return 1; } // One line from commands file char *line; // One of the commands char command; // Rest of the command char rcommand[256]; // Variable for error handling int rc; while((line = read_line(commands)) != NULL) { sscanf(line, "%c %255[^\n]", &command, rcommand); switch(command) { case 'P': add_person_to_list(rcommand, &people); break; case 'F': rc = add_friends(rcommand, &people); if(rc == -1) { fprintf(stderr, "You cannot add yourself as your friend!\n"); } break; case 'R': rc = remove_friends(rcommand, &people); break; case 'B': block_user(rcommand, &people); break; case 'U': unblock_user(rcommand, &people); break; case 'S': list_friends_same_university(rcommand, &people); break; case 'A': list_all_friends(rcommand, &people); break; case 'C': list_common(rcommand, &people); break; case 'M': message(rcommand, &people); break; default: break; } memset(rcommand, 0, sizeof(rcommand)); // Free the line, since our work with it is done. free(line); } // CLEANUP element *current; while(NULL != people.head) { current = people.head; people.head = current->next; person *p = current->data; free(p->name); free(p->university); element *friend; while(NULL != p->friend_list.head) { friend = p->friend_list.head; p->friend_list.head = friend->next; free(friend); } free(current->data); free(current); } // Close our file handle fclose(commands); return 0; }