90 lines
2.5 KiB
Markdown
90 lines
2.5 KiB
Markdown
# 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`](../DirectoryScanSender), and both projects can work together out of the box with the current default settings.
|
|
|
|
## Companion Project
|
|
|
|
- Sender counterpart: [`DirectoryScanSender`](../DirectoryScanSender)
|
|
- Shared default TCP port: `7156`
|
|
|
|
## Shared Protocol
|
|
|
|
Both projects use the same message format:
|
|
|
|
```text
|
|
<path>|<length>|<content>\r\n\r\n
|
|
```
|
|
|
|
- `path`: file path string sent by the sender
|
|
- `length`: declared payload length
|
|
- `content`: 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 `output` directory next to the executable
|
|
- Creates subdirectories when needed
|
|
- Skips existing files (no overwrite)
|
|
- Prevents writing outside the `output` directory
|
|
|
|
## 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 `output` directory 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:
|
|
|
|
```bash
|
|
dotnet build
|
|
dotnet run --project DirectoryScanReceiver
|
|
```
|
|
|
|
The server prints messages such as:
|
|
|
|
- `Started Server!`
|
|
- `Waiting for data!`
|
|
|
|
## Test Message Example
|
|
|
|
Using `nc` (netcat):
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
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 [`DirectoryScanSender`](../DirectoryScanSender) or another sender that follows the same message format.
|
|
- The current defaults match the local `DirectoryScanSender` project (`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.
|