How to transfer documents to Google Docs using command line or Python scripts

I need to move a bunch of files to Google Docs but I only have terminal access on my Linux machine. No GUI interface available, just SSH connection to work with.

I’m wondering if there’s a method to accomplish this task using either bash scripts or Python code. I have tons of documents that need to be uploaded and doing it manually through a web browser isn’t an option for me right now.

Has anyone successfully automated this process before? Any suggestions on which approach would work better - shell scripting or Python programming? I’m comfortable with both but just need to know if it’s actually doable through command line tools.

Would really appreciate any guidance on this since I’m stuck with only terminal access for now.

Python with the Google Drive API is your best bet. I’ve done similar bulk uploads using google-api-python-client and it works great over SSH. First, set up OAuth2 credentials through Google Cloud Console and download the JSON file to your server. The tricky part is authentication since you can’t open a browser - use the out-of-band flow or run auth on a machine with a browser and copy the credentials over. After that, uploading is straightforward with the drive service API. I batch uploads and add retry logic for network issues. Files convert to Google Docs automatically when you set the right MIME type during upload.

gdrive CLI tool is worth checking out. Used it last year for a similar situation - had to upload hundreds of PDFs from a headless server. Installation’s easy (just download the binary), and auth works fine without GUI since it gives you a URL to visit on another machine. Clean syntax: gdrive upload --convert filename.docx handles conversion to Google Docs format automatically. Performance was solid, though I hit some rate limiting with large batches. Added sleep intervals between uploads and it worked perfectly. The convert flag’s key if you want actual Google Docs instead of just stored files.

rclone is perfect for this. It’s built for bulk transfers and works great with Google Drive. Setup’s easy, then just run rclone copy /your/docs gdrive:folder and you’re done. Way better than dealing with APIs.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.