1. gdrive

https://github.com/prasmussen/gdrive

1.1. 설치

wget <https://github.com/prasmussen/gdrive/releases/download/2.1.1/gdrive_2.1.1_linux_386.tar.gz>
tar -xvf gdrive_2.1.1_linux_386.tar.gz
❯ ./gdrive about
Authentication needed
Go to the following url in your browser:
[<https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=state>](<https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=state>)

Enter verification code: 4/1AX4XfWi7t38yxEd3O-qE2M7mpNDMSTJOZJu04H4v1HJ9T6PSLqHKbqLgu68
User: SAT PC, [[email protected]](<mailto:[email protected]>)
Used: 559.4 GB
Free: 1.6 TB
Total: 2.2 TB
Max upload size: 5.2 TB

Untitled

1.2. 업로드

./gdrive upload --parent {dst_folder_name} --recursive {src_folder_path}
❯ ./gdrive upload --recursive /nas/k8s/dev/data/ftp-hkb/NIMS/validation/test
Creating directory test
Uploading /nas/k8s/dev/data/ftp-hkb/NIMS/validation/test/COMS_EA_BIN_201907_11.tar.gz
134.2 MB/2.7 GB, Rate: 13.1 MB/s

1.3. Python

from __future__ import print_function

import os.path

from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

# If modifying these scopes, delete the file token.json.
SCOPES = ['<https://www.googleapis.com/auth/drive>']

def main():
    """Shows basic usage of the Drive v3 API.
    Prints the names and ids of the first 10 files the user has access to.
    """
    creds = None
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('/path/google/token.json'):
        creds = Credentials.from_authorized_user_file('/path/google/token.json', SCOPES)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                '/path/google/client_secret.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('/path/google/token.json', 'w') as token:
            token.write(creds.to_json())

    try:
        service = build('drive', 'v3', credentials=creds)

        # Call the Drive v3 API
        results = service.files().list(
            pageSize=10, fields="nextPageToken, files(id, name)").execute()
        items = results.get('files', [])

        if not items:
            print('No files found.')
            return
        print('Files:')
        for item in items:
            print(u'{0} ({1})'.format(item['name'], item['id']))
    except HttpError as error:
        # TODO(developer) - Handle errors from drive API.
        print(f'An error occurred: {error}')

if __name__ == '__main__':
    main()