This project provides a simple FTP-like service built with Golang, using SQLite as the metadata storage. The service allows you to upload, get, and delete files from a local directory.
Make sure you have Golang installed on your machine. You can download it from https://golang.org/dl/.
git clone https://github.com/initeshjain/golang-ftp-service.git
cd golang-ftp-service
Run the following commands to install the required dependencies:
go get -u github.com/gin-gonic/gin
go get -u github.com/mattn/go-sqlite3
go build -o ftp-service main.go
./ftp-service
The server will start on http://localhost:8080.
You can configure the service by modifying the config.json file. Update the UploadDir to specify the local directory path where uploaded files will be stored.
{
"UploadDir": "/path/to/upload/directory",
"DbPath": "ftp_metadata.db"
}
To upload a file, you can use curl from the command line. Replace <file_path>
and <your_server_url>
with the actual file path and server URL.
curl -X POST -F "file=@<file_path>/example.txt" http://localhost:8080/upload
To retrieve a file, use the below endpoint in your browser run below command. Replace <filename>
with the name of the file you want to retrieve.
curl -X GET http://localhost:8080/get/<filename> -o <filename>
To delete a file, use the following endpoint in your browser or any HTTP client. Replace <filename>
with the name of the file you want to delete.
curl -X DELETE http://localhost:8080/delete/<filename>
No authentication is required as it's intended for local development purposes. This is a basic implementation, and you may need to enhance security and error handling based on your requirements.
Connect with me on social media: