Skip to content

A multi-threaded client-server file sharing application built with Python and Tkinter.

Notifications You must be signed in to change notification settings

egeyardimci/file-server-408

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Server 408

A multi-threaded client-server file sharing application built with Python and Tkinter. This application allows multiple clients to connect to a centralized server for uploading, downloading, listing, and deleting files with a graphical user interface.

Features

Server Features

  • Multi-threaded architecture supporting concurrent client connections
  • Secure file storage with user-based ownership
  • Persistent file registry that survives server restarts
  • Real-time logging and monitoring through GUI console
  • File upload/download with progress tracking
  • Client notification system for file downloads
  • User authentication with unique username enforcement

Client Features

  • Intuitive graphical user interface
  • File upload with drag-and-drop support
  • File download capabilities
  • Server file listing and browsing
  • File deletion (owner permissions required)
  • Real-time notifications for file activity
  • Connection status monitoring

Architecture

The application uses a dual-socket architecture:

  • Primary Socket: Command handling and communication protocol
  • Secondary Socket: High-speed file transfer operations

Communication Protocol

All data transfer follows a standardized packet structure:

  • 4-byte length prefix (big-endian) followed by actual data
  • Command codes for different operations (UPLOAD, DOWNLOAD, LIST, DELETE, NOTIFY)
  • Acknowledgment system (OK/NOK) for operation confirmation

Project Structure

file-server-408/
├── server/
│   ├── server_backend.py    # Core server logic and networking
│   ├── server_gui.py        # Server GUI implementation
│   └── parser.py            # Protocol parsing utilities
├── client/
│   ├── client_backend.py    # Client networking and logic
│   ├── client_gui.py        # Client GUI implementation
│   ├── parser.py            # Protocol parsing utilities
│   └── test_files/          # Sample test files
└── README.md

Requirements

  • Python 3.6 or higher
  • Tkinter (included with most Python installations)
  • Standard library modules: socket, threading, os, re, time

Installation

  1. Clone the repository:
git clone <repository-url>
cd file-server-408
  1. No additional dependencies required - uses Python standard library only.

Usage

Starting the Server

  1. Navigate to the server directory:
cd server
  1. Run the server GUI:
python server_gui.py
  1. Configure server settings:

    • IP Address: Enter the server IP (e.g., localhost or 127.0.0.1)
    • Port: Choose a port number (e.g., 8080)
    • Directory: Select where uploaded files will be stored
  2. Click "Start" to begin accepting client connections

Connecting Clients

  1. Navigate to the client directory:
cd client
  1. Run the client GUI:
python client_gui.py
  1. Enter connection details:

    • IP Address: Server IP address
    • Port: Server port number
    • User Name: Unique username for this session
  2. Click "Connect" to establish connection

File Operations

Upload Files

  1. Click "Upload File" button
  2. Select file from file dialog
  3. File will be uploaded and stored with format: username_filename

Download Files

  1. Click "Retrieve Server Data" to refresh file list
  2. Select a file from the list
  3. Click "Download" to save file locally

Delete Files

  1. Select a file you own from the list
  2. Click "Delete" to remove file from server
  3. Only file owners can delete their files

List Files

  • Click "Retrieve Server Data" to see all available files
  • Files are displayed with owner information

File Storage

  • Server files are stored in the configured directory
  • Files are prefixed with the owner's username: username_filename.ext
  • File registry is maintained in permanent-file-registry for persistence
  • Server state is preserved across restarts

Network Protocol

Command Codes

  • DOWNLOAD = 1: Request file download
  • UPLOAD = 2: Request file upload
  • LIST = 3: Request file listing
  • DELETE = 4: Request file deletion
  • NOTIFY = 5: Server notification to clients

Acknowledgment Codes

  • OK = 10: Operation successful
  • NOK = 11: Operation failed

Data Transfer Flow

  1. Client sends command on primary socket
  2. Server acknowledges and prepares secondary socket
  3. File data transfers on secondary socket (port + 1)
  4. Secondary socket closes after transfer completion

Security Features

  • Username uniqueness enforcement
  • File ownership verification for delete operations
  • Connection authentication and validation
  • Isolated file storage per user

Error Handling

  • Connection failure recovery
  • File operation error reporting
  • Server disconnection detection
  • Invalid file access prevention

Development

Key Components

Server Backend (server/server_backend.py)

  • Server class handles all networking and file operations
  • Multi-threaded client connection management
  • Persistent file registry system

Client Backend (client/client_backend.py)

  • Client class manages server communication
  • Asynchronous command handling
  • File transfer operations

Protocol Parser (server/parser.py)

  • Standardized packet sending/receiving functions
  • Command and acknowledgment handling
  • Binary data serialization

Troubleshooting

Common Issues

  1. "Username already taken"

    • Choose a different username
    • Wait for previous session to timeout
  2. "Connection failed"

    • Verify server is running
    • Check IP address and port settings
    • Ensure firewall allows connections
  3. "File upload failed"

    • Check file permissions
    • Verify sufficient disk space on server
    • Ensure file is not locked by another application
  4. "Cannot delete file"

    • Only file owners can delete their files
    • Refresh file list to see current ownership

Port Configuration

  • Default setup uses consecutive ports (e.g., 8080 for commands, 8081 for data)
  • Ensure both ports are available and not blocked by firewall

Purpose

This project is built for educational purposes.

About

A multi-threaded client-server file sharing application built with Python and Tkinter.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages