2.5 KiB
DirectoryScanReceiver
DirectoryScanReceiver is a small TCP server that receives file data over a simple delimiter-based protocol and writes files into an output directory.
It is the receiver counterpart to DirectoryScanSender, and both projects can work together out of the box with the current default settings.
Companion Project
- Sender counterpart:
DirectoryScanSender - Shared default TCP port:
7156
Shared Protocol
Both projects use the same message format:
<path>|<length>|<content>\r\n\r\n
path: file path string sent by the senderlength: declared payload lengthcontent: payload content
Multiple messages can be sent over the same TCP connection, each terminated by \r\n\r\n.
Features
- Listens for TCP connections on port
7156 - Accepts multiple file messages over a connection
- Writes files to an
outputdirectory next to the executable - Creates subdirectories when needed
- Skips existing files (no overwrite)
- Prevents writing outside the
outputdirectory
Runtime Behavior
- The server waits for incoming TCP connections.
- Each valid message is parsed and written as one file.
- Empty or invalid messages are ignored.
- The
outputdirectory is cleared once when the application starts.
Console output includes connection events, received payload sizes, and written file paths.
Requirements
- .NET SDK with support for
net10.0
Build and Run
From the repository root:
dotnet build
dotnet run --project DirectoryScanReceiver
The server prints messages such as:
Started Server!Waiting for data!
Test Message Example
Using nc (netcat):
printf 'hello.txt|5|hello\r\n\r\n' | nc 127.0.0.1 7156
This writes hello.txt into the receiver's output directory.
Subdirectories are also supported:
printf 'subdir/note.txt|11|hello world\r\n\r\n' | nc 127.0.0.1 7156
Notes
- The protocol is simple and delimiter-based.
- The receiver is intended to be used with
DirectoryScanSenderor another sender that follows the same message format. - The current defaults match the local
DirectoryScanSenderproject (localhost:7156). - The service uses plain TCP and does not include authentication or encryption.
License and Disclaimer
This project may be used, copied, modified, and shared freely.
It is provided as is, without warranty of any kind. The author is not liable for any damages or losses resulting from its use.