void do_cmd_appe(session_t *pses) { //打开文件 int fd = open(pses->arg, O_CREAT | O_WRONLY, 0666); if(fd < 0) { ftp_reply(pses->ctrl_fd, FTP_UPLOADFAIL, "Could not create file."); return; } //给文件加写锁 if(lock_file_write(fd) == -1) { ftp_reply(pses->ctrl_fd, FTP_UPLOADFAIL, "Could not create file."); return; } int flag = upload_common(pses, fd, 1); //关闭数据套接字 close(pses->data_fd); pses->data_fd = -1; //关闭文件 unlock_file(fd); close(fd); if(flag == 0) { //226 ftp_reply(pses->ctrl_fd, FTP_TRANSFEROK, "Transfer complete."); } else if(flag == -1) { ftp_reply(pses->ctrl_fd, FTP_BADSENDNET, "Failure writting to local file."); } else if(flag == -2) { //451 ftp_reply(pses->ctrl_fd, FTP_BADSENDNET, "Failure reading from network stream."); } }
static void do_appe(session_t *sess) { upload_common(sess, 1); }
static void do_stor(session_t *sess) { upload_common(sess, 0); }
/** *do_stor - 以APPE方式上传文件 *@sess:会话结构体 */ void ftpproto::do_appe(session_t* sess) { upload_common(sess,1);//1表示APPE方式 }
/** *do_stor - 以STOR方式上传文件 *@sess:会话结构体 */ void ftpproto::do_stor(session_t* sess) { upload_common(sess,0);//0表示STOR方式 }