Secure Static IP for Python SFTP using QuotaGuard Shield

Learn how to securely route Python SFTP file transfers through a QuotaGuard Shield proxy. Includes code examples and Dockerfile.

Prerequisites

pip install paramiko

Instructions

Run example
QUOTAGUARDSHIELD_URL=... bin/qgtunnel python app.py

Be sure to set QUOTAGUARDSHIELD_URL to your Connection URL from the QuotaGuard Dashboard.

Test in Docker
docker build -t qg-shield-python-sftp-paramiko-example .
docker run -e QUOTAGUARDSHIELD_URL=... qg-shield-python-sftp-paramiko-example

Code Samples

App.py
#/usr/bin/env python
import paramiko

if __name__ == '__main__':
    tport = paramiko.Transport(('test.rebex.net',2222))
    tport.connect(username='demo',password='password')

    sftp = paramiko.SFTPClient.from_transport(tport)
    sftp.get('readme.txt','readme.txt')
    sftp.close()

    tport.close()
Docker File
FROM python:latest

#install paramiko
RUN pip install -U pip && \
    pip install paramiko

WORKDIR /app

#install qgtunnel
RUN curl https://s3.amazonaws.com/quotaguard/qgtunnel-latest.tar.gz | tar xz
ENV QGTUNNEL_DEBUG true

COPY .qgtunnel .qgtunnel
COPY app.py app.py
COPY .run.sh .run.sh

ENTRYPOINT [ "/bin/bash", "/app/.run.sh" ]