https://github.com/basemax/windows-linux-file-downloader-c
File Downloader in C: A simple C program to download files over HTTP using sockets. Cross-platform support for both Windows and Linux.
https://github.com/basemax/windows-linux-file-downloader-c
c clang download-file file-downloader http http-download http-file-download network socket
Last synced: 6 months ago
JSON representation
File Downloader in C: A simple C program to download files over HTTP using sockets. Cross-platform support for both Windows and Linux.
- Host: GitHub
- URL: https://github.com/basemax/windows-linux-file-downloader-c
- Owner: BaseMax
- License: gpl-3.0
- Created: 2024-09-04T12:51:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-07T14:40:23.000Z (about 1 year ago)
- Last Synced: 2025-03-28T17:08:10.482Z (7 months ago)
- Topics: c, clang, download-file, file-downloader, http, http-download, http-file-download, network, socket
- Language: C
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Windows/Linux File Downloader in C
A C program that demonstrates how to download a file over HTTP from a server using sockets. The program is cross-platform, working on both Windows and Linux systems.
## Features
- **Cross-platform support:** Works on both Windows and Linux.
- **Socket:** Uses sockets to connect to a server and download a file.
- **Minimal dependencies:** Only standard C libraries and platform-specific socket libraries are used.## Requirements
### Windows
- GCC (MinGW or similar)
- Winsock2 library (comes with Windows)### Linux
- GCC
- Standard POSIX libraries (usually included with most Linux distributions)## Building the Project
### Windows
To build the program on Windows, use the following command:
```bash
gcc downloader.c -o downloader -g -Wextra -std=c11 -lws2_32
```### Linux
To build the program on Linux, use the following command:
```bash
gcc downloader.c -o downloader -g -Walloca -Wextra -Wall -fsanitize=address,undefined -std=c11
```## Usage
After compiling, you can run the program as follows:
```bash
./downloader
```The program will connect to example.com and download the file located on remote server, saving it locally as `downloaded_file.log`.
### Customization
- **Hostname:** The hostname to connect to is currently set to example.com.
- **Path:** The path to the file on the server is set to /file.txt.
- **Port:** The port used for the connection is 80 (HTTP).You can customize these values by modifying the following lines in downloader.c:
```c
const char *hostname = "example.com";
const char *path = "/file.txt";
const char *port = "80";
```### Platform-Specific Notes
#### Windows
The program uses Winsock2 for socket communication. Ensure that Winsock2 is initialized using WSAStartup() before any socket operations and cleaned up using WSACleanup() after all operations are done.
#### Linux
The program uses POSIX-compliant socket functions and does not require any special initialization or cleanup beyond the normal opening and closing of sockets.
## Troubleshooting
- Socket Connection Issues: Ensure that the server you are trying to connect to is reachable and that the port is open.
- Compilation Errors: Make sure you are using GCC with the appropriate flags as described in the "Building the Project" section.
- File Writing Issues: Ensure that you have write permissions to the directory where the file will be saved.### Author
Max Base
### License
This project is licensed under the GPL-3.0 License. See the LICENSE file for more details.
Copyright 2024, Max Base