You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过终端从Google Drive「与我共享」下载12GB压缩文件

Alright, let's tackle this—you've got access to a 12GB compressed file in a shared Google Drive folder, and you want to pull it down via terminal using wget or Python. Here are two solid methods that work well for large files:

Method 1: Download with wget

Google Drive requires a confirmation step for large files, so we'll use a command that automatically handles this cookie-based verification. Here's what to run:

# Replace "your_file_name.zip" with your desired output filename
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1PMJEk3hT-_ziNhSPkU9BllLYASLzN7TL' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1PMJEk3hT-_ziNhSPkU9BllLYASLzN7TL" -O your_file_name.zip && rm -rf /tmp/cookies.txt

Key Notes:

  • The command creates a temporary cookie file to bypass the large-file confirmation prompt, then deletes it once done.
  • If the download gets interrupted, add the -c flag to resume from where it left off:
    wget -c --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=...[rest of the URL]..." -O your_file_name.zip
    
Method 2: Download with Python (Requests Library)

For more control (especially with large files), use a Python script that streams the download in chunks to avoid overwhelming your memory.

First, install the requests library if you don't have it:

pip install requests

Then create a script (e.g., gdrive_download.py) with this code:

import requests

# Replace with your file ID (from your shared link: 1PMJEk3hT-_ziNhSPkU9BllLYASLzN7TL)
FILE_ID = '1PMJEk3hT-_ziNhSPkU9BllLYASLzN7TL'
OUTPUT_FILENAME = 'your_file_name.zip'

def download_gdrive_file(file_id, output_filename):
    url = f"https://docs.google.com/uc?export=download&id={file_id}"
    session = requests.Session()

    # Fetch the initial response to get the confirmation token
    response = session.get(url, stream=True)
    confirmation_token = None
    for key, value in response.cookies.items():
        if key.startswith('download_warning'):
            confirmation_token = value
            break

    # If we got a token, re-request with confirmation
    if confirmation_token:
        url += f"&confirm={confirmation_token}"
        response = session.get(url, stream=True)

    # Stream the download in 10MB chunks (adjust chunk_size if needed)
    chunk_size = 10 * 1024 * 1024  # 10MB
    with open(output_filename, 'wb') as f:
        for chunk in response.iter_content(chunk_size=chunk_size):
            if chunk:
                f.write(chunk)
                f.flush()  # Ensure data is written to disk immediately

    print(f"Download completed! File saved as {output_filename}")

if __name__ == "__main__":
    download_gdrive_file(FILE_ID, OUTPUT_FILENAME)

Run the script with:

python gdrive_download.py

Bonus: Download the entire shared folder

If you ever need to grab the whole folder instead of just the single file, use the gdown library:

pip install gdown
gdown --folder https://drive.google.com/drive/folders/13cx4SBFLTX8CqIqjjec9-pcadGaJ0kNj

Just note that gdown might require you to log in via browser if the folder has restricted access (though since you already have permission, it should work smoothly).

内容的提问来源于stack exchange,提问作者dJOKER_dUMMY

火山引擎 最新活动