How to upload a file to a server?
Question: I want to upload files to my servers at Digital Ocean and AWS. I can do that
via the terminal using scp or sftp, but I want to automate this and do it in
Python or any other programming language. In case of Python, how can I upload
a file to a server in high level, should I use sftp client? **Any other
options?**


Answer: You can use pysftp package;

    
    
    import pysftp
    
    with pysftp.Connection('hostname', username='me', password='secret') as sftp:
        with sftp.cd('public')              # temporarily chdir to public
            sftp.put('/my/local/filename')  # upload file to public/ on remote
    
        sftp.get_r('myfiles', '/backup')    # recursively copy myfiles/ to local
    

<https://pypi.python.org/pypi/pysftp>

It also uses paramiko internally I guess which can be used for ssh, sftp etc.
<http://docs.paramiko.org/en/1.17/api/sftp.html>

