void get_list(struct s_static_socket *br) { FILE *list; char buffer[BUF_SIZE]; size_t octet; if (open_dataconnection(br) == -1) return ; if (br->pasv == -1) xwrite(br->cs, "425 Can't open data connection\n", 31); else { my_putstr("LIST REQUEST\n"); if (get_list_popen(br, &list) == -1) return ; while ((octet = fread(buffer, 1, BUF_SIZE, list)) > 0) xwrite(br->pasv, buffer, octet); xclose(br->pasv); br->pasv = -1; xfpurge(list); usleep(500000); xwrite(br->cs, "226 Transfer complete\n", 22); xpclose(list); } }
static void cmd_retr(const char *arg, struct tcp_pcb *pcb, struct ftpd_msgstate *fsm) { vfs_file_t *vfs_file; vfs_stat_t st; vfs_stat(fsm->vfs, arg, &st); if (!VFS_ISREG(st.st_mode)) { send_msg(pcb, fsm, msg550); return; } vfs_file = vfs_open(fsm->vfs, arg, "rb"); if (!vfs_file) { send_msg(pcb, fsm, msg550); return; } send_msg(pcb, fsm, msg150recv, arg, st.st_size); if (open_dataconnection(pcb, fsm) != 0) { vfs_close(vfs_file); return; } fsm->datafs->vfs_file = vfs_file; fsm->state = FTPD_RETR; }
static void cmd_list_common(const char *arg, struct tcp_pcb *pcb, struct ftpd_msgstate *fsm, int shortlist) { vfs_dir_t *vfs_dir; char *cwd; cwd = vfs_getcwd(fsm->vfs, NULL, 0); if ((!cwd)) { send_msg(pcb, fsm, msg451); return; } vfs_dir = vfs_opendir(fsm->vfs, cwd); free(cwd); if (!vfs_dir) { send_msg(pcb, fsm, msg451); return; } if (open_dataconnection(pcb, fsm) != 0) { vfs_closedir(vfs_dir); return; } fsm->datafs->vfs_dir = vfs_dir; fsm->datafs->vfs_dirent = NULL; if (shortlist != 0) fsm->state = FTPD_NLST; else fsm->state = FTPD_LIST; send_msg(pcb, fsm, msg150); }
static void cmd_stor(const char *arg, struct tcp_pcb *pcb, struct ftpd_msgstate *fsm) { vfs_file_t *vfs_file; vfs_file = vfs_open(fsm->vfs, arg, "wb"); if (!vfs_file) { send_msg(pcb, fsm, msg550); return; } send_msg(pcb, fsm, msg150stor, arg); if (open_dataconnection(pcb, fsm) != 0) { vfs_close(vfs_file); return; } fsm->datafs->vfs_file = vfs_file; fsm->state = FTPD_STOR; }