Download Files from Google Drive to VPS

Downloading files from Google Drive to a VPS is more complex than usual because Google uses confirmation redirects for large files and requires authentication for private files. Here are the methods that really work.

02

Method 1: gdown (recommended, public files)

gdown is a Python tool specifically for Google Drive. It automatically handles redirects and confirmation cookies.

bash
# Install gdown
pip install gdown --break-system-packages
# or
pip3 install gdown --break-system-packages

# Download a file via shareable URL
gdown "https://drive.google.com/file/d/FILE_ID/view"

# Or directly with file ID
gdown FILE_ID

# Download to specific directory
gdown FILE_ID -O /root/downloads/

# Download entire folder
gdown --folder https://drive.google.com/drive/folders/FOLDER_ID

How to find the FILE_ID

From the file URL:

https://drive.google.com/file/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms/view ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this is the FILE_ID
03

Method 2: curl with cookie (large public files)

Google Drive redirects files >100MB through a confirmation page. This method bypasses it:

bash
# First request: get confirmation cookie
curl -c /tmp/gdrive-cookie.txt -s \
  "https://drive.google.com/uc?export=download&id=FILE_ID" > /tmp/gdrive-check.txt

# Extract confirmation token
CONFIRM=$(grep -o 'confirm=[^&"]*' /tmp/gdrive-check.txt | head -1 | cut -d= -f2)

# Second request: download with token
curl -L -b /tmp/gdrive-cookie.txt \
  "https://drive.google.com/uc?export=download&confirm=${CONFIRM}&id=FILE_ID" \
  -o filename.zip

# Cleanup
rm /tmp/gdrive-cookie.txt /tmp/gdrive-check.txt

Simpler one-liner script

bash
# Function to add to ~/.bashrc
gdrive_download() {
  local FILE_ID="$1"
  local OUTPUT="${2:-gdrive_file}"
  gdown "$FILE_ID" -O "$OUTPUT"
}
# Usage: gdrive_download 1BxiMVs0XRA... filename.zip
04

Method 3: rclone (private files and large folders)

For private files or large folders, rclone is the most robust solution. Requires OAuth authorization once.

bash
# Install rclone
curl https://rclone.org/install.sh | bash

# Configure Google Drive (requires browser once)
rclone config
# Follow the wizard:
# n → new remote
# name: gdrive
# type: drive (Google Drive)
# client_id and secret: leave empty to use rclone's
# scope: 1 (full access) or 2 (read-only)
# Authentication: open link in browser and authorize

After configuration:

bash
# List files in Drive root
rclone ls gdrive:

# Download a specific file
rclone copy "gdrive:Folder/filename.zip" /root/downloads/

# Download entire folder
rclone copy "gdrive:Backup Server" /root/downloads/backup/ --progress

# Sync (deletes files no longer on Drive)
rclone sync "gdrive:Backup" /root/backup/ --progress

# Speed up download with parallel transfers
rclone copy "gdrive:file.zip" /root/ --transfers 8 --progress

If configuring rclone on a VPS without browser, use rclone config and choose "Use auto config? n": it will provide a URL to open on your local PC.

05

Speed up downloads

Increase parallel transfers with rclone

bash
# Use 16 parallel threads (great for large files or folders)
rclone copy "gdrive:Backup" /root/backup/ \
  --transfers 16 \
  --checkers 8 \
  --buffer-size 256M \
  --drive-chunk-size 128M \
  --progress

Check actual speed

bash
# Install speedtest to compare
pip install speedtest-cli --break-system-packages
speedtest-cli

# Google Drive speed depends on server region.
# European servers typically reach 100-500 Mbps on Drive.
06

Common issues

"Too many requests" or slow download

Google Drive enforces rate limiting. Solutions:

bash
# Add delay between files
rclone copy "gdrive:Folder" /root/ --transfers 4 --tpslimit 5

# Or use automatic backoff
rclone copy "gdrive:Folder" /root/ --retries 10 --low-level-retries 10

Downloaded file corrupted or HTML instead of file

bash
# Verify the downloaded file is not an error HTML page
file filename.zip
head -c 200 filename.zip

# If shows HTML, the URL or ID is wrong, or the file is private
# Use gdown which handles these cases automatically

Private file (not publicly shared)

For non-public files, only rclone with OAuth authentication works. Cannot download them with curl or gdown without credentials.

07

Upload files to Google Drive from VPS

bash
# Upload a file with rclone
rclone copy /root/backup.tar.gz "gdrive:Backup Server/" --progress

# Upload entire folder
rclone copy /var/backups/ "gdrive:VPS Backups/$(date +%Y-%m-%d)/" --progress

# Bidirectional sync
rclone sync /root/data/ "gdrive:Data/" --progress

Useful for automatic backups to Google Drive: see also Backup with Rclone.

DeluxHost, founded in 2023, offers high-quality hosting solutions for various digital needs. We provide shared hosting, VPS, and dedicated servers with advanced security and global data centers.

© DeluxHost, All rights reserved. | VAT Number : IT17734661006
All Systems Operational