int do_RNTO(ftp_session *s, char *param) { int len; char arg[MAX_FTP_PATH], ftp_path[MAX_FTP_PATH]; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (s->prev_command != cmd_RNFR) return 503; if (!parse_dir(s->dir, arg, ftp_path)) return 550; if (!ftp_to_fs(ftp_path, arg)) return 550; if (!(is_file_exists(s->rename) || is_dir_exists(s->rename))) return 550; if (!MoveFile(s->rename, arg)) return 450; return 250; }
int do_RNFR(ftp_session *s, char *param) { int len; char arg[MAX_FTP_PATH], ftp_path[MAX_FTP_PATH]; s->curr_command = cmd_NOOP; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (readonly) return 550; if (!parse_dir(s->dir, arg, ftp_path)) return 550; if (!ftp_to_fs(ftp_path, arg)) return 550; if (!(is_file_exists(arg) || is_dir_exists(arg))) return 550; s->curr_command = cmd_RNFR; strcpy(s->rename, arg); ftp_printf(s->control, "350 File exists, ready for destination name.\r\n"); return 0; }
int win_io_base::make_dir(const TCHAR* p_dir) { if(is_dir_exists(p_dir)) return 0; // SECURITY_ATTRIBUTES sa; // SECURITY_DESCRIPTOR sd; // // InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); // SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE); // sa.nLength = sizeof(SECURITY_ATTRIBUTES); // sa.bInheritHandle = TRUE; // sa.lpSecurityDescriptor = &sd; // // assert(CreateDirectory(p_dir,&sa)); return _wmkdir(p_dir); }
int do_DELE_RMD(ftp_session *s, char *param) { int len, attr, del_mode; char arg[MAX_FTP_PATH], ftp_path[MAX_FTP_PATH]; MATCH_SP(param); len = get_string(param, arg, sizeof(arg)); if (len == 0) return 501; param += len; MATCH_CRLF(param); if (readonly) return 550; if (!parse_dir(s->dir, arg, ftp_path)) return 550; if (!ftp_to_fs(ftp_path, arg)) return 550; del_mode = s->curr_command == cmd_DELE; if (del_mode && !is_file_exists(arg)) return 550; if (!del_mode && !is_dir_exists(arg)) return 550; attr = GetFileAttributes(arg); SetFileAttributes(arg, 0); if (del_mode ? !DeleteFile(arg) : !RemoveDirectory(arg)) { SetFileAttributes(arg, attr); return 450; } return 250; }
int is_ftp_dir_exists(const char *dir) { char drive[MAX_PATH]; int i, type; if (strcmp(dir, "/") == 0) return TRUE; if (dir[2] != 0 && dir[2] != '/') return FALSE; drive[0] = dir[1]; strcpy(&drive[1], ":\\"); type = GetDriveType(drive); if (type == DRIVE_UNKNOWN || type == DRIVE_NO_ROOT_DIR) return FALSE; strcpy(&drive[3], &dir[3]); for (i = 3; drive[i] != 0; i++) if (drive[i] == '/') drive[i] = '\\'; return is_dir_exists(drive); }
int WinIO::make_dir(const char* p_dir) { if(is_dir_exists(p_dir)) return IOBase::NORMAL_SUCCESS; return _mkdir(p_dir) ? IOBase::NORMAL_SUCCESS : IOBase::NORMAL_FAILED; }
int do_LIST_NLST(ftp_session *s, char *param) { char *p, *dir, buf[MAX_BUFFER], ftp_dir[MAX_FTP_PATH]; int len, size; SOCKET sockfd; SYSTEMTIME stime; dir = s->dir; if (*param == ' ') { param++; /* Fix: for something like LIST -la /etc (e.g: on Midnight Commander) * Not compatible with standard */ if (*param == '-') { param++; while (*param != ' ' && *param != 0) param++; if (*param == ' ') param++; } len = get_string(param, buf, sizeof(buf)); if (param == 0) return 501; if (!parse_dir(dir, buf, ftp_dir)) return 450; param += len; dir = ftp_dir; } MATCH_CRLF(param); ftp_printf(s->control, reply_150); sockfd = ftp_connect(s); if (sockfd == -1) return 425; size = 0; GetLocalTime(&stime); if (strcmp(dir, "/") == 0) { char drive[4]; char list_buf[128]; char *list_item[32]; int list_dir[32]; int list_count, i; list_count = 0; p = list_buf; for (strcpy(drive, "a:\\"); drive[0] <= 'z'; drive[0]++) { int type = GetDriveType(drive); if (type == DRIVE_FIXED || (list_cdrom && type == DRIVE_CDROM) || (list_floppy && type == DRIVE_REMOVABLE)) { list_item[list_count] = p; list_dir[list_count++] = TRUE; *p++ = drive[0]; *p++ = 0; } } #ifdef USE_SPECIAL_FILE for (i = 0; special_file[i] != 0; i++) { list_item[list_count] = p; list_dir[list_count++] = FALSE; strcpy(p, special_file[i]); p += strlen(p)+1; } #endif for (i = 0; i < list_count; i++) { if (s->curr_command == cmd_LIST) { char ro = (readonly || !list_dir[i]) ? '-' : 'w'; char dir = list_dir[i] ? 'd' : '-'; char exec = list_dir[i] ? 'x' : '-'; size += sprintf(&buf[size], "%cr%c%cr%c%cr%c%c 1 %-8s %-8s %10d %s %2d %02d:%02d %s\r\n", dir, ro, exec, ro, exec, ro, exec, ftp_owner, ftp_group, 0, month[stime.wMonth-1], stime.wDay, stime.wHour, stime.wMinute, list_item[i]); } else size += sprintf(&buf[size], "%s\r\n", list_item[i]); if (size >= MAX_BUFFER_FILLED) { my_send(sockfd, buf, MAX_BUFFER_FILLED, 0); size -= MAX_BUFFER_FILLED; memmove(buf, &buf[MAX_BUFFER_FILLED], size); } } } else { WIN32_FIND_DATA find_data; HANDLE handle; ftp_to_fs(dir, buf); strcpy(ftp_dir, buf); if (is_dir_exists(ftp_dir)) { len = strlen(ftp_dir); if (ftp_dir[len-1] != '\\') ftp_dir[len++] = '\\'; strcpy(&ftp_dir[len], "*.*"); } handle = FindFirstFile(ftp_dir, &find_data); if (handle != INVALID_HANDLE_VALUE) { do { char year[6], dir, ro, exec; SYSTEMTIME time; if (strcmp(find_data.cFileName, ".") == 0 || strcmp(find_data.cFileName, "..") == 0) continue; dir = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 'd' : '-'; ro = (find_data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) || readonly ? '-' : 'w'; exec = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 'x' : '-'; FileTimeToSystemTime(&find_data.ftLastWriteTime, &time); if (time.wYear == stime.wYear) sprintf(year, "%02d:%02d", time.wHour, time.wMinute); else sprintf(year, "%d", time.wYear); if (s->curr_command == cmd_LIST) { size += sprintf(&buf[size], "%cr%c%cr%c%cr%c%c 1 %-8s %-8s %10lu %s %2d %5s %s\r\n", dir, ro, exec, ro, exec, ro, exec, ftp_owner, ftp_group, find_data.nFileSizeLow, month[time.wMonth-1], time.wDay, year, find_data.cFileName); } else size += sprintf(&buf[size], "%s\r\n", find_data.cFileName); if (size >= MAX_BUFFER_FILLED) { my_send(sockfd, buf, MAX_BUFFER_FILLED, 0); size -= MAX_BUFFER_FILLED; memmove(buf, &buf[MAX_BUFFER_FILLED], size); } } while (FindNextFile(handle, &find_data)); FindClose(handle); } } if (size >= 0) my_send(sockfd, buf, size, 0); closesocket(sockfd); return 226; }