Download File from Link

!pip install requests pydrive tqdm -q
Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (2.32.3)
Requirement already satisfied: pydrive in /usr/local/lib/python3.11/dist-packages (1.3.1)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests) (3.4.2)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests) (2.4.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests) (2025.4.26)
Requirement already satisfied: google-api-python-client>=1.2 in /usr/local/lib/python3.11/dist-packages (from pydrive) (2.169.0)
Requirement already satisfied: oauth2client>=4.0.0 in /usr/local/lib/python3.11/dist-packages (from pydrive) (4.1.3)
Requirement already satisfied: PyYAML>=3.0 in /usr/local/lib/python3.11/dist-packages (from pydrive) (6.0.2)
Requirement already satisfied: httplib2<1.0.0,>=0.19.0 in /usr/local/lib/python3.11/dist-packages (from google-api-python-client>=1.2->pydrive) (0.22.0)
Requirement already satisfied: google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0 in /usr/local/lib/python3.11/dist-packages (from google-api-python-client>=1.2->pydrive) (2.38.0)
Requirement already satisfied: google-auth-httplib2<1.0.0,>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from google-api-python-client>=1.2->pydrive) (0.2.0)
Requirement already satisfied: google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5 in /usr/local/lib/python3.11/dist-packages (from google-api-python-client>=1.2->pydrive) (2.24.2)
Requirement already satisfied: uritemplate<5,>=3.0.1 in /usr/local/lib/python3.11/dist-packages (from google-api-python-client>=1.2->pydrive) (4.1.1)
Requirement already satisfied: pyasn1>=0.1.7 in /usr/local/lib/python3.11/dist-packages (from oauth2client>=4.0.0->pydrive) (0.6.1)
Requirement already satisfied: pyasn1-modules>=0.0.5 in /usr/local/lib/python3.11/dist-packages (from oauth2client>=4.0.0->pydrive) (0.4.2)
Requirement already satisfied: rsa>=3.1.4 in /usr/local/lib/python3.11/dist-packages (from oauth2client>=4.0.0->pydrive) (4.9.1)
Requirement already satisfied: six>=1.6.1 in /usr/local/lib/python3.11/dist-packages (from oauth2client>=4.0.0->pydrive) (1.17.0)
Requirement already satisfied: googleapis-common-protos<2.0.0,>=1.56.2 in /usr/local/lib/python3.11/dist-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client>=1.2->pydrive) (1.70.0)
Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<7.0.0,>=3.19.5 in /usr/local/lib/python3.11/dist-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client>=1.2->pydrive) (5.29.4)
Requirement already satisfied: proto-plus<2.0.0,>=1.22.3 in /usr/local/lib/python3.11/dist-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client>=1.2->pydrive) (1.26.1)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.11/dist-packages (from google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client>=1.2->pydrive) (5.5.2)
Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in /usr/local/lib/python3.11/dist-packages (from httplib2<1.0.0,>=0.19.0->google-api-python-client>=1.2->pydrive) (3.2.3)
import requests
from tqdm import tqdm  # For a clean progress bar

# Step 1: Get URL from user
url = input("Enter the download URL: ").strip()
filename = url.split('/')[-1].split('?')[0]

# Step 2: Download with progress bar
def download_file(url, filename):
    print(f"Downloading from {url}...")
    with requests.get(url, stream=True) as r:
        r.raise_for_status()
        total_size = int(r.headers.get('content-length', 0))
        block_size = 8192  # 8 KB
        t = tqdm(total=total_size, unit='B', unit_scale=True, desc=filename)
        with open(filename, 'wb') as f:
            for chunk in r.iter_content(chunk_size=block_size):
                f.write(chunk)
                t.update(len(chunk))
        t.close()
    print(f"Download complete: {filename}")
    return filename

# Run download
download_file(url, filename)
Enter the download URL: https://ftp.osuosl.org/pub/osgeo/download/qgis/windows/QGISQT6-OSGeo4W-3.42.3-1.msi?MU
Downloading from https://ftp.osuosl.org/pub/osgeo/download/qgis/windows/QGISQT6-OSGeo4W-3.42.3-1.msi?MU...
✅ Download complete: QGISQT6-OSGeo4W-3.42.3-1.msi
'QGISQT6-OSGeo4W-3.42.3-1.msi'

Upload to Google Drive

# Authenticate
from google.colab import auth
auth.authenticate_user()

# Imports
import os
import google.auth
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload

# Get user credentials and build the Drive API service
creds, _ = google.auth.default()
service = build('drive', 'v3', credentials=creds)

# Ask for the file to upload
filename = input("Enter the filename to upload to Google Drive: ").strip()

# Upload file to Google Drive
if os.path.exists(filename):
    print(f"Uploading {filename}...")
    file_metadata = {'name': filename}
    media = MediaFileUpload(filename, resumable=True)
    uploaded_file = service.files().create(
        body=file_metadata,
        media_body=media,
        fields='id'
    ).execute()

    # Make the file publicly accessible
    service.permissions().create(
        fileId=uploaded_file['id'],
        body={'type': 'anyone', 'role': 'reader'}
    ).execute()

    # Display shareable link
    print("Upload complete!")
    print(f"File link: https://drive.google.com/file/d/{uploaded_file['id']}/view")
else:
    print("File does not exist.")
Enter the filename to upload to Google Drive: /content/QGISQT6-OSGeo4W-3.42.3-1.msi
Uploading /content/QGISQT6-OSGeo4W-3.42.3-1.msi...
✅ Upload complete!
🔗 File link: https://drive.google.com/file/d/1tHcqbmqoywiq0cWJViOZLRTdPiK4GKrW/view