As I mentioned in the last post there is a bug with CWD command. I modified ftpsrv_cwd(FTPSRV_SESSION_STRUCT* session) in ftpsrv_cmd.c
int32_t ftpsrv_cwd(FTPSRV_SESSION_STRUCT* session)
{
int error;
char* path;
char* new_path;
uint32_t path_size;
void* dir_ptr;
char* full_path;
uint32_t wrong_path;
if (session->cmd_arg == NULL)
{
session->message = (char*) ftpsrvmsg_badsyntax;
return(FTPSRV_ERROR);
}
ftpsrv_convert_percents(session->cmd_arg);
path = ftpsrv_strip_path_delimiters(session->cmd_arg);
path_size = strlen(path)+1;
/* Get absolute directory path in filesystem */
full_path = ftpsrv_get_full_path(session, path, &wrong_path);
if (full_path == NULL)
{
if (wrong_path)
{
session->message = (char*) ftpsrvmsg_cd_error;
}
else
{
session->message = (char*) ftpsrvmsg_no_memory;
}
return(FTPSRV_ERROR);
}
/* Try to open directory only for reading so we know if directory exists */
dir_ptr = _io_mfs_dir_open(session->fs_ptr, full_path, "*r");
if (dir_ptr == NULL)
{
session->message = (char*) ftpsrvmsg_cd_error;
_mem_free(full_path);
return(FTPSRV_ERROR);
}
_io_mfs_dir_close(dir_ptr);
/* Get path relative to FTP root so we can set it as new current directory */
new_path = ftpsrv_get_relative_path(session, full_path);
_mem_free(full_path);
if (!new_path)
{
session->message = (char*) ftpsrvmsg_no_memory;
return(FTPSRV_ERROR);
}
/* If everything went right, set path we chdir'd to as session current path */
if (session->cur_dir)
{
_mem_free(session->cur_dir);
}
/*FIXME (SM)*/
new_path[0]='\\';
new_path[1]='\0';
session->cur_dir = new_path;
return (ftpsrv_pwd(session));
}
now it works for root directory.
Cheers,
Sam