diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-04-28 15:08:16 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-04-28 15:08:16 +0300 |
commit | e5f70efffb9f0ff3f71b7abc4bdc992b343a0dc2 (patch) | |
tree | cd7905cadeeb01c0ec4fcac5b02bb3fbc4c99ad4 /FtpServer | |
parent | 5b2be402f7142ee7a10efc02b47a13bee1da78b9 (diff) |
FTP server is much more compatible with FTP clients
Diffstat (limited to 'FtpServer')
-rw-r--r-- | FtpServer/IFileSystemHandler.cs | 12 | ||||
-rw-r--r-- | FtpServer/NesMiniFileSystemHandler.cs | 27 | ||||
-rw-r--r-- | FtpServer/Session.cs | 20 |
3 files changed, 55 insertions, 4 deletions
diff --git a/FtpServer/IFileSystemHandler.cs b/FtpServer/IFileSystemHandler.cs index 950f7034..057d8946 100644 --- a/FtpServer/IFileSystemHandler.cs +++ b/FtpServer/IFileSystemHandler.cs @@ -178,6 +178,18 @@ namespace mooftpserv ResultOrError<FileSystemEntry[]> ListEntries(string path);
/// <summary>
+ /// LIST: Return a raw output of 'ls' command.
+ /// </summary>
+ /// <param name="path">
+ /// The relative or absolute path of an existing directory or file.
+ /// Can be null or empty to return the current directory.
+ /// </para>
+ /// <return>
+ /// Raw output of 'ls' command
+ /// </return>
+ ResultOrError<string> ListEntriesRaw(string path);
+
+ /// <summary>
/// SIZE: Gets the size of a file in bytes.
/// </summary>
/// <returns>
diff --git a/FtpServer/NesMiniFileSystemHandler.cs b/FtpServer/NesMiniFileSystemHandler.cs index 11cb7956..5fb8b0ab 100644 --- a/FtpServer/NesMiniFileSystemHandler.cs +++ b/FtpServer/NesMiniFileSystemHandler.cs @@ -51,7 +51,15 @@ namespace mooftpserv public ResultOrError<string> ChangeDirectory(string path)
{
string newPath = ResolvePath(path);
- currentPath = newPath;
+ try
+ {
+ clovershell.ExecuteSimple("cd \""+newPath+"\"", 1000 ,true);
+ currentPath = newPath;
+ }
+ catch (Exception ex)
+ {
+ return MakeError<string>(ex.Message);
+ }
return MakeResult<string>(newPath);
}
@@ -207,6 +215,23 @@ namespace mooftpserv return MakeResult<FileSystemEntry[]>(result.ToArray());
}
+ public ResultOrError<string> ListEntriesRaw(string path)
+ {
+ if (path.StartsWith("-"))
+ path = ". " + path;
+ string newPath = ResolvePath(path);
+ List<string> result = new List<string>();
+ try
+ {
+ var lines = clovershell.ExecuteSimple("ls " + newPath, 1000, true);
+ return MakeResult<string>(lines);
+ }
+ catch (Exception ex)
+ {
+ return MakeError<string>(ex.Message);
+ }
+ }
+
public ResultOrError<long> GetFileSize(string path)
{
string newPath = ResolvePath(path);
diff --git a/FtpServer/Session.cs b/FtpServer/Session.cs index dd2ac996..42075372 100644 --- a/FtpServer/Session.cs +++ b/FtpServer/Session.cs @@ -460,8 +460,9 @@ namespace mooftpserv {
// apparently browsers like to pass arguments to LIST
// assuming they are passed through to the UNIX ls command
+ /*
arguments = RemoveLsArgs(arguments);
-
+
ResultOrError<FileSystemEntry[]> ret = fsHandler.ListEntries(arguments);
if (ret.HasError)
{
@@ -470,6 +471,16 @@ namespace mooftpserv }
SendData(MakeStream(FormatDirList(ret.Result)));
+ */
+ ResultOrError<string> ret = fsHandler.ListEntriesRaw(arguments);
+ if (ret.HasError)
+ {
+ Respond(500, ret.Error);
+ break;
+ }
+
+ SendData(MakeStream(ret.Result));
+
break;
}
case "STAT":
@@ -1092,8 +1103,11 @@ namespace mooftpserv timestr += time.ToString(" dd hh:mm");
string mode = entry.Mode;
- result.AppendFormat("{0}{4} 1 owner group {1} {2} {3}\r\n",
- dirflag, size, timestr, entry.Name, mode.Substring(1) ?? "rwxr--r--");
+ if (string.IsNullOrEmpty(mode))
+ mode = dirflag + "rwxr--r--";
+
+ result.AppendFormat("{0} 1 owner group {1} {2} {3}\r\n",
+ mode, size, timestr, entry.Name);
}
return result.ToString();
|