cpmove or .tar.gz archive to your laptop just to upload it back to Google Drive—or vice versa—burns hours of time and risks broken transfers if your connection drops.
Because Google Colab provisions an ephemeral Linux container running on Google's datacenter network, you can mount your Google Drive directly to the container's filesystem and run standard Linux tools (cp, rsync, wget, curl, scp, gdown, and rclone) at gigabit speeds without routing a single byte through your local machine.
1. Mounting Google Drive in Google Colab
- Open Google Colab (
colab.research.google.com) and click New Notebook. - Run the following Python cell to mount your Google Drive at
/content/drive:
PYTHON
from google.colab import drive
drive.mount('/content/drive')- Click Connect to Google Drive in the prompt, select your Google account, and grant access. Once mounted, your primary Drive contents live inside
/content/drive/MyDrive.
!):
BASH
!df -h /content/drive/MyDrive
!ls -lah "/content/drive/MyDrive"2. Copying Files Between Two Different Google Drive Accounts
Step 1: Share the Source Folder and Add a Shortcut
- On the Source Google Drive, right-click the file or folder you want to transfer, select Share, and grant at least Viewer access to your Destination Google Drive account.
- Log in to the Destination Google Drive, open Shared with me, right-click the shared folder or file, and click Organize -> Add shortcut.
- Select My Drive as the shortcut location.
Step 2: Copy the Contents via Colab
BASH
!ls -la "/content/drive/MyDrive"Important Note on Modern Google Drive Shortcuts: Depending on how the shortcut was created, Google Drive mounts folder shortcuts either directly underRun/content/drive/MyDrive/<Shortcut_Name>or resolves them inside the hidden/content/drive/.shortcut-targets-by-id/<Folder_ID>/<Folder_Name>path. Usingrsyncwith-L(--copy-links) orcp -rLensures symlinks are dereferenced and the actual files are copied rather than just the shortcut pointer.
rsync to copy the entire shared folder into a new real directory inside your destination Drive with live progress output:
BASH
!mkdir -p "/content/drive/MyDrive/Transferred_Backups"
!rsync -avhP --copy-links "/content/drive/MyDrive/Shared_Folder_Shortcut/" "/content/drive/MyDrive/Transferred_Backups/"cp:
BASH
!cp -rvL "/content/drive/MyDrive/Shared_Folder_Shortcut/." "/content/drive/MyDrive/Transferred_Backups/"3. Pulling Files from Web Hosting or Any URL Directly to Google Drive (wget & curl)
Direct Download with wget
%cd (Colab's magic command that persists directory changes across command lines in a cell) or pass the output directory directly to wget -P:
BASH
!mkdir -p "/content/drive/MyDrive/Server_Backups"
!wget -c "YOUR_DIRECT_BACKUP_URL/full-backup-2026-10-30.tar.gz" -P "/content/drive/MyDrive/Server_Backups/"wget flags for large hosting backups:
-c(--continue): Resumes a partially downloaded file if the connection resets.-O "/content/drive/MyDrive/Server_Backups/custom-name.tar.gz": Saves the file under a specific filename.--user=USERNAME --password='PASSWORD': Authenticates against HTTP Basic Auth or FTP endpoints.
Multi-Connection High-Speed Download with aria2c
aria2 in the Colab runtime to pull the file over 16 parallel connections:
BASH
!apt-get update -qq && apt-get install -y -qq aria2
!aria2c -x 16 -s 16 -d "/content/drive/MyDrive/Server_Backups" -o "full-backup.tar.gz" "YOUR_DIRECT_BACKUP_URL/full-backup-2026-10-30.tar.gz"4. Pulling Files from Web Hosting via SSH/SFTP (rsync & scp)
Option A: Using an Ephemeral SSH Key (Recommended)
~/.ssh/authorized_keys (or cPanel -> SSH Access) on your hosting server:
BASH
!ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -N "" -q
!cat /root/.ssh/id_ed25519.pubrsync over SSH (replace 22 if your hosting provider uses a custom SSH port like 2222 or 7822):
BASH
!rsync -avzP -e "ssh -p 22 -o StrictHostKeyChecking=no" username@your-server-hostname:/home/username/backups/ "/content/drive/MyDrive/Server_Backups/"Option B: Using Password Authentication with sshpass
BASH
!apt-get update -qq && apt-get install -y -qq sshpass
!sshpass -p 'YOUR_SSH_PASSWORD' rsync -avzP -e "ssh -p 22 -o StrictHostKeyChecking=no" username@your-server-hostname:/home/username/backups/site.tar.gz "/content/drive/MyDrive/Server_Backups/"5. Moving Files from Google Drive to Your Web Hosting Server
gdown or rclone.
Method 1: Push from Google Colab to Hosting via rsync or scp
/content/drive/MyDrive straight to your server's /home/username/ directory:
BASH
!rsync -avzP -e "ssh -p 22 -o StrictHostKeyChecking=no" "/content/drive/MyDrive/Server_Backups/full-backup.tar.gz" username@your-server-hostname:/home/username/scp:
BASH
!scp -P 22 -o StrictHostKeyChecking=no "/content/drive/MyDrive/Server_Backups/full-backup.tar.gz" username@your-server-hostname:/home/username/Method 2: Pull Directly on the Hosting Server via gdown (No Colab Needed)
wget often fails on large Google Drive files due to the virus-scan confirmation page), use gdown:
- Set the file permission in Google Drive to Anyone with the link (Viewer) and copy the File ID from the URL (
drive.google.com/file/d/<FILE_ID>/view). - Run the following on your hosting server via SSH:
BASH
pip3 install --user gdown
~/.local/bin/gdown --id YOUR_GOOGLE_DRIVE_FILE_ID -O backup.tar.gz6. Extracting or Compressing Archives Directly Inside Google Colab
wp-content/uploads or node_modules) to Google Drive one by one is slow because Google Drive throttles high API request rates per second. Always compress folders into a single archive before moving them, or extract them on the Colab local SSD (/content) before pushing to a remote server.
Create a .tar.gz Archive in Google Drive
BASH
!tar -czvf "/content/drive/MyDrive/Server_Backups/site-archive.tar.gz" -C "/content/drive/MyDrive/Raw_Site_Files" .Extract a .tar.gz or .zip Archive in Google Drive
BASH
# Extract .tar.gz
!tar -xzvf "/content/drive/MyDrive/Server_Backups/site-archive.tar.gz" -C "/content/drive/MyDrive/Extracted_Site/"
# Extract .zip
!unzip -q "/content/drive/MyDrive/Server_Backups/site-archive.zip" -d "/content/drive/MyDrive/Extracted_Site/"7. Flushing the Google Drive Cache Before Disconnecting
/content/drive through a FUSE filesystem layer that buffers writes in the background. If you transfer a 20 GB file and immediately terminate the Colab runtime, the file may not finish syncing to Google Drive.
Always run drive.flush_and_unmount() at the end of your transfer session to guarantee every byte is committed to Google Drive's backend storage:
PYTHON
from google.colab import drive
drive.flush_and_unmount()
print("All pending transfers synced safely to Google Drive.")