github.com/dnutiu/simplFT@v0.0.0-20181023061248-df4b14cdce57/README.md (about)

     1  # simplFT
     2  
     3  [![Go Report Card](https://goreportcard.com/badge/github.com/Metonimie/simplFT)](https://goreportcard.com/report/github.com/Metonimie/simplFT)
     4  [![Build Status](https://travis-ci.org/metonimie/simplFT.svg?branch=master)](https://travis-ci.org/metonimie/simplFT)
     5  
     6  This project was made for the purpose of me to learn and understand Go better and also for the Computer Networking class
     7  that I took in Fall 2017 at UPT.
     8  
     9  The scope of this project is to implement a simple server that handles multiple clients and allows the clients to
    10  execute commands on it.
    11  
    12  ## Commands
    13  
    14  The server accepts the following commands:
    15  
    16  ```
    17  get <filename> - Download the requested filename.
    18  ls             - List the files in the current directory.
    19  cd             - Changes the directory.
    20  clear          - Clear the screen.
    21  exit           - Close the connection with the server.c
    22  pic <filename> - Returns the ascii art of an image. :-)
    23  ```
    24  
    25  #### Sending commands via netcat
    26  
    27  To grab a file the following command can be send:
    28  
    29  ```echo "get file.txt" | nc ip port > lfile.txt```
    30  
    31  If someone wishes to send multiple commands, the following syntax
    32  can be used:
    33  
    34  ```(echo "get file1.txt" & echo "get file2.txt") | nc ip port > concatenated.txt```
    35  
    36  #### The upload server
    37  
    38  If the upload server is running, the user will be able to put files
    39  on the **absoluteServePath**. After the file is uploaded successfully,
    40  if the timeout is not reached, the user will get back the filename.
    41  
    42  To send data to the upload server, the following command can be used:
    43  
    44  ```nc ip port < gopher.png```
    45  
    46  ## Configuration
    47  
    48  The server can be configured via command line flags with the -config option,
    49  specifying a path to the configuration file.
    50  If no configuration file is provided the server will run with the default settings.
    51  
    52  Sample Configuration File:
    53  ```
    54  {
    55      "address": "localhost",
    56      "port": 8080,
    57      "maxDirDepth": 30,
    58      "absoluteServePath": "/Users/denis/Dropbox/Pictures/CuteAvatars",
    59      "pic": {
    60          "color": true,
    61          "x": 197,
    62          "y": 50
    63      },
    64      "upload": {
    65          "enabled": false,
    66          "directory": "upload",
    67          "timeout": 5,
    68          "address": "localhost",
    69          "port": 8081
    70      }
    71  }
    72  ```
    73  
    74  ```./simplFT --help``` will list all the command line flags with the associated help text.
    75  
    76  The **config.json** file contains the following settings:
    77  
    78  1. address           - The address on which to serve
    79  
    80  2. port              - The port
    81  
    82  3. maxDirDepth       - The maximum depth the user can go into directories. A value of 30 means the user can cd into max 30 dirs.
    83  
    84  4. absoluteServePath - The path from where to serve the files.
    85  
    86  5. pic               - The X and Y max size for the pic command. A value of 0 means original size.
    87  
    88  6. upload            - Settings for the upload server.
    89  If one of the settings are changed, the server will reload the configuration.
    90  Except for the absoluteServePath.
    91  
    92  ## Docker
    93  
    94  To build the image run: ```docker build -t simplft .``` and to run the server:
    95  
    96  ```
    97  docker run -d \
    98    -it \
    99    --name devtest \
   100    --mount type=bind,source="/Users/denis/Downloads",target=/externalVolume \
   101    -p 8080:8080 -p 8081:8081 \
   102    simplft
   103  ```
   104  
   105  * ```-p PORT1:PORT2``` - PORT1 is the host machine's port mapped to the container's PORT2
   106  * ```source="/Users/denis/Downloads"``` - This path should be changed to the path from where you want to serve files.
   107  
   108  To stop the server you will first need to identify the running container and the stop it via 
   109  ```docker container stop CONTAINER ID```
   110  
   111  ##### Stopping the server
   112  
   113  ```
   114  ➜  server git:(master) ✗ docker container ls
   115  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                             NAMES
   116  90b6f00b1331        simplft             "./simplFTP -confi..."   2 minutes ago       Up 2 minutes        0.0.0.0:8081->8081/tcp, 0.0.0.0:32768->8080/tcp   devtest
   117  ➜  server git:(master) ✗ docker container stop 90b6f00b1331
   118  90b6f00b1331
   119  ```
   120  
   121  #### Example docker config
   122  
   123  ```json
   124  {
   125      "address": "0.0.0.0",
   126      "port": 8080,
   127      "maxDirDepth": 30,
   128      "absoluteServePath": "/externalVolume",
   129      "pic": {
   130          "color": true,
   131          "x": 197,
   132          "y": 50
   133      },
   134      "upload": {
   135          "enabled": true,
   136          "directory": "upload",
   137          "timeout": 5,
   138          "address": "0.0.0.0",
   139          "port": 8081
   140      }
   141  }
   142  ```