Compare commits
2 Commits
5671a7aac8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 47218e028a | |||
| cba657bc44 |
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
||||||
@@ -69,6 +69,7 @@ static class DataHandler
|
|||||||
var di = new DirectoryInfo(dir);
|
var di = new DirectoryInfo(dir);
|
||||||
|
|
||||||
if (!di.Exists) di.Create();
|
if (!di.Exists) di.Create();
|
||||||
|
|
||||||
if (fi.Exists) return;
|
if (fi.Exists) return;
|
||||||
|
|
||||||
Console.WriteLine($"Writing File: {newPath}");
|
Console.WriteLine($"Writing File: {newPath}");
|
||||||
@@ -82,7 +83,7 @@ internal class Server
|
|||||||
|
|
||||||
public Server(int port)
|
public Server(int port)
|
||||||
{
|
{
|
||||||
_listener = new TcpListener(IPAddress.Parse("127.0.0.1"), port);
|
_listener = new TcpListener(IPAddress.Any, port);
|
||||||
_listener.Start();
|
_listener.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +98,6 @@ internal class Server
|
|||||||
|
|
||||||
public void Receiver()
|
public void Receiver()
|
||||||
{
|
{
|
||||||
if(Directory.Exists(DataHandler.OutputDir)) Directory.Delete(DataHandler.OutputDir, true);
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if(!_listener.Pending()) continue;
|
if(!_listener.Pending()) continue;
|
||||||
@@ -156,6 +155,8 @@ public static class Program
|
|||||||
{
|
{
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
|
if(Directory.Exists(DataHandler.OutputDir)) Directory.Delete(DataHandler.OutputDir, true);
|
||||||
|
|
||||||
var server = new Server(7156);
|
var server = new Server(7156);
|
||||||
Console.WriteLine("Started Server!");
|
Console.WriteLine("Started Server!");
|
||||||
while (true)
|
while (true)
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
# 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.
|
||||||
Reference in New Issue
Block a user