Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy folder from server(Linux) to local machine(windows) in python

How to copy a folder from Server (linux) to a local machine (windows) in python.

I tried with the given code but it did not work

from distutils.dir_util import copy_tree
copy_tree("source_path ","destination_path")

I used copy_tree command to copy a folder on my local machine but when I used the same command to copy a folder from server to local machine then it did not work.

Any other method is there? Or any changes needed?

like image 857
python Avatar asked Aug 15 '26 04:08

python


1 Answers

You need to use SSH, SCP, or SFTP to transfer files from host to host.

I do this a lot and like to use SSH and SCP. You can run and SSH server on your windows machine using OpenSSH. Here is a good set of instructions from WinSCP: https://winscp.net/eng/docs/guide_windows_openssh_server.

I recommend using Paramiko for SSH with Python. Here is a good answer showing how this works with python: https://stackoverflow.com/a/38556344/634627.

If you set up OpenSSH, you could also do this with SFTP, sometimes I find this is more suitable that SCP. Here is a good answer showing how that works: https://stackoverflow.com/a/33752662/634627

The trick is getting OpenSSH running on your Windows host and setting up SSH keys so your server can authenticate to your localhost.

like image 155
Mike Avatar answered Aug 17 '26 17:08

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!