这是indexloc提供的服务,不要输入任何密码
Skip to content

harshrai654/shareit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShareIT

ShareIT is a command-line tool written in Go that enables easy file sharing from a laptop or PC to mobile devices over the same local area network using QR codes.

Features

  • Seamless File Sharing: Share files quickly and securely within the same local network.
  • Cross-Platform Compatibility: Supports macOS, Linux, and Windows.
  • QR Code Generation: Automatically generates a QR code for easy file access on mobile devices.
  • JWT Token Security: Ensures secure file transfer using JWT tokens.
  • Pause and Resume: Supports content-range headers for pausing and resuming downloads.
  • Automatic Server Management: CLI tool manages the server process, including starting and stopping the server as needed.

How It Works

Components

There are two main components in ShareIT:

  1. shareit.server: The server process that handles file requests.
  2. shareit.cli: The command-line interface for initiating file shares.

Workflow

shareit-workflow

  1. CLI Command Execution: To share a file to devices in the local network you will need the Absolute address of the file in the local machine.
    shareit.cli.<darwin|linux|windows>[.exe] -filepath "/path/to/file"
  2. File and Server Validation:
    • The CLI checks the validity of the file path.
    • It checks if the server process is running by attempting a TCP dial-up.
    • If the server process is not running, the CLI starts the server in a new process.
    • The CLI reads the server.pid file to get the server's HTTP port. If the file is missing or the dial-up fails, the CLI starts a new server process.
  3. Server Initialization:
    • The server starts an HTTP server and a Unix domain socket server.
    • It writes the HTTP port to the server.pid file.
  4. File Sharing Process:
    • The CLI fetches the local IP of all network interfaces.
    • It generates a random secret and creates a JWT token with the file path as the payload.
    • The CLI shares the secret with the server via a Unix socket along with the file path. Each file share generates a unique secret.
    • The CLI appends the local IP and port to the token and generates a QR code from this string, displaying it in the terminal.
  5. Mobile Device Access:
    • Scanning the QR code on a mobile device sends a request to the server with the token value.
    • The server decodes the token using the secret to verify the request's authenticity.
    • The server reads the file from the given file path and provides it for download.
    • The server supports pause and resume functionality through content-range headers.
  6. Security:
    • JWT tokens mask the file path parameter and ensure that only links generated by the CLI can be used for downloading files.

Installation Instructions

You can download and install the latest CLI and Server executables using the following command:

For Linux

bash -c 'REPO="harshrai654/shareit"; DEST_DIR="$HOME/.local/bin/shareit"; ASSETS=("shareit.cli.linux" "shareit.server.linux"); mkdir -p $DEST_DIR; chmod -R 775 $DEST_DIR; for ASSET in "${ASSETS[@]}"; do URL=$(curl -s https://api.github.com/repos/$REPO/releases/latest | grep browser_download_url | grep $ASSET | cut -d\" -f4); curl -L -o "$DEST_DIR/$ASSET" "$URL"; chmod +x "$DEST_DIR/$ASSET"; export PATH=$PATH:$DEST_DIR; done'

For MacOS

sh -c 'REPO="harshrai654/shareit"; DEST_DIR="$HOME/.local/bin/shareit"; ASSETS=("shareit.cli.darwin" "shareit.server.darwin"); mkdir -p $DEST_DIR; chmod -R 775 $DEST_DIR; for ASSET in "${ASSETS[@]}"; do URL=$(curl -s https://api.github.com/repos/$REPO/releases/latest | grep browser_download_url | grep $ASSET | cut -d\" -f4); curl -L -o "$DEST_DIR/$ASSET" "$URL"; chmod +x "$DEST_DIR/$ASSET"; export PATH=$PATH:$DEST_DIR; done'

For Windows (Powershell)

Run following commands in Powershell with admin access In windows 11 you can open terminal, right click the powershell tab and run it as administrator and then paste the below commands":

$repo = "harshrai654/shareit"
$destDir = "$env:USERPROFILE\AppData\Local\shareit\bin"
$assets = @("shareit.cli.windows.exe", "shareit.server.windows.exe")

if (-Not (Test-Path -Path $destDir)) {
    New-Item -ItemType Directory -Path $destDir -Force
}

try {
    $releaseInfo = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases/latest"
} catch {
    Write-Error "Failed to get release information from GitHub: $_"
    exit 1
}

foreach ($asset in $assets) {
    $url = $releaseInfo.assets | Where-Object { $_.name -eq $asset } | Select-Object -ExpandProperty browser_download_url
    if ($url) {
        $destPath = Join-Path -Path $destDir -ChildPath $asset
        Invoke-WebRequest -Uri $url -OutFile $destPath
        Write-Host "Downloaded $asset to $destPath"
    } else {
        Write-Host "Asset $asset not found in the latest release."
    }
}
try {
    New-NetFirewallRule -DisplayName "Allow Port 8965" -Direction Inbound -Protocol TCP -LocalPort 8965 -Action Allow -ErrorAction Stop
    Write-Host "Firewall rule created to allow port 8965"
} catch {
    Write-Error "Failed to create firewall rule: $_"
}

# Add $destDir to the PATH environment variable if it's not already there
$currentPath = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::User)
if (-Not ($currentPath -split ";" | ForEach-Object { $_.Trim() } | Where-Object { $_ -eq $destDir })) {
    $newPath = "$currentPath;$destDir"
    [System.Environment]::SetEnvironmentVariable("PATH", $newPath, [System.EnvironmentVariableTarget]::User)
    Write-Host "Added $destDir to the PATH environment variable"
} else {
    Write-Host "$destDir is already in the PATH environment variable"
}

Future Features

  • Basic Authentication: Share a user-entered password along with the JWT secret for basic authentication before file download.
  • Auto Termination: Automatically terminate the server process after a period of idle behavior to prevent resource leaks.

About

A file sharing CLI tool, based on QR codes and local area network.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published