FubarDevelopment / FtpServer

Portable FTP server written in .NET
http://fubardevelopment.github.io/FtpServer/
MIT License
482 stars 163 forks source link

Server does not check if current directory (still) exists. #25

Closed mvacha closed 5 years ago

mvacha commented 6 years ago

Steps to reproduce:

  1. User1 connects, creates directory abc and changes current directory to abc
  2. User2 connects, deletes directory abc
  3. User1 attempts to do some action with his current directory (e.g. upload a file)
  4. DirectoryNotFoundException is thrown and 501 Syntax error in parameters or arguments. is returned to User1

Affected commands: At least PWD, CWD, STOR

Log with full exception:

[LOG - 192,168,1,121,205,45] [TRC] STOR cam2_802814741_20180421185452334_MOTION_DETECTION.jpg
[LOG - 192,168,1,121,205,45] [DBG] 150 Opening connection for data transfer.
[LOG - 192,168,1,121,205,45] [ERR] Error while processing background command STOR cam2_802814741_20180421185452334_MOTION_DETECTION.jpg
[LOG - 192,168,1,121,205,45] [EXP] System.AggregateException: One or more errors occurred. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\aa\bb\cc\192.168.1.121\2018_04_21-2018_04_21\cam2_802814741_20180421185452334_MOTION_DETECTION.jpg'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.FileInfo.Create()
   at FubarDev.FtpServer.FileSystem.DotNet.DotNetFileSystem.<CreateAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at FubarDev.FtpServer.CommandHandlers.StorCommandHandler.<Process>d__3.MoveNext()
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\aa\bb\cc\192.168.1.121\2018_04_21-2018_04_21\cam2_802814741_20180421185452334_MOTION_DETECTION.jpg'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.FileInfo.Create()
   at FubarDev.FtpServer.FileSystem.DotNet.DotNetFileSystem.<CreateAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at FubarDev.FtpServer.CommandHandlers.StorCommandHandler.<Process>d__3.MoveNext()<---

[LOG - 192,168,1,121,205,45] [WRN] 501 Syntax error in parameters or arguments.
fubar-coder commented 5 years ago

Trying to fix such things is an endless effort and usually not worth it. I'll just let the underlying OS/file system handle this problem