Transfer file to linux server with Python

Asked

Viewed 816 times

0

Hello,

I’m looking to make a file Python that transfers all files from a local folder in my Windows for a specific path on my server Centos 7. At first that server is in my local network, but it would be interesting to transfer to a external server.

Any hint of how I can do this procedure with python will be of great help!

Any questions, I’m at your disposal.

  • Does Centos have an SSH or FTP server? Windows has "samba"?

  • 1

    Opa, yes I have access by SSH, I usually use the Putty. I will do the pysftp test and give a return, thanks!

1 answer

1


If Centos has access via SSH/SFTP you can install the module https://pypi.python.org/pypi/pysftp and run a python script like this:

import pysftp

with pysftp.Connection('NOME DO HOST', username='USUARIO', password='SENHA') as sftp:
    with sftp.cd('public'):             # navega para uma pasta especifica
        sftp.put('c:/foo/bar/baz.txt')  # faz o upload para a pasta public

note: the installation seems not available via pip, you can download the .tar.gz

Browser other questions tagged

You are not signed in. Login or sign up in order to post.