Python Forum
Copying files from a remote Windows station - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Copying files from a remote Windows station (/thread-34277.html)

Pages: 1 2


Copying files from a remote Windows station - tester_V - Jul-14-2021

Greetings to those that do not sleep! Wink
I have a bunch of remote hosts(windows), each host has a windows based system connected to it (I call it a Station).
I need to copy files from each Station to my server.
I made a little script and I can copy it to all hosts but the big question is how I can call/ran the script from my server?
script
from pathlib import Path
import shutil

l_dst = "c:\\02"
ip_tm ="DESK-2"
r_src = "\\\\"+itm+"\\c$\\01"
for eitem in Path(r_src).iterdir() :
    print(f" Item {eitem}")
    if eitem.is_file() :
        print(f" It is file {eitem}")
        try:
            shutil.copy(eitem,l_dst)
        except OSError  as rr :
            print(f" Cannot Copy File {rr}")
Thank you.


RE: Copying files from a remote Windows station - Gribouillis - Jul-14-2021

You could perhaps use the rpyc module to do this. You'll need to run a rpyc server on some machines and you can run python code by connecting to these servers.


RE: Copying files from a remote Windows station - tester_V - Jul-14-2021

(Jul-14-2021, 06:26 AM)Gribouillis Wrote: You could perhaps use the rpyc module to do this. You'll need to run a rpyc server on some machines and you can run python code by connecting to these servers.

I cannot install any " a rpyc server on some machines ", is there anything else I could use?
Thank you.


RE: Copying files from a remote Windows station - Gribouillis - Jul-15-2021

If you cannot run programs on the machines and there are no servers such as ssh servers or others and there are no shared directories, I don't see how you could copy the files.


RE: Copying files from a remote Windows station - tester_V - Jul-15-2021

I'm a Power shell script to start a Python script on a remote PC.
I was just wondering is there a "Python" way to do the same thing.
Invoke-Command -Computer DESK2 -Scriptblock {python.exe 'C:\02\LB_scripts\Python_1.py'}



RE: Copying files from a remote Windows station - Gribouillis - Jul-15-2021

You could probably run the powershell command from Python by using the subprocess module. Apart from that, if you can run a python program with this command, you could also probably start a Python server on the remote machine with the same command.


RE: Copying files from a remote Windows station - tester_V - Jul-16-2021

Sorry for asking the same question again!
I'm not a programmer and getting confused easily.
It is the only way to start a python script on a remote PC is to use 'rpyc', there are no other 'modules' or some kind of a hack...

Thank you.


RE: Copying files from a remote Windows station - Gribouillis - Jul-16-2021

I don't know if there are 'hacks' to do this, but there are more standard ways to connect to a remote computer. For example if there is a SSH server running on the remote computer, you can connect as a user to this SSH server. In python you could do this with a module such as Paramiko.


RE: Copying files from a remote Windows station - tester_V - Jul-16-2021

Thank you! Great help!


RE: Copying files from a remote Windows station - snippsat - Jul-16-2021

(Jul-16-2021, 01:47 AM)tester_V Wrote: It is the only way to start a python script on a remote PC is to use 'rpyc', there are no other 'modules' or some kind of a hack...
The most basic way is to use SCP(Secure Copy Protocol) or rsync.
When on Windows i always use cmder which has SCP, rsync and SSH build in.
Example.
# To server
scp -P 2400 image.png [email protected]:/var/www/python-forum.io/uploads 

# From server this will save file in C:\code:
scp -P 2400 image.png [email protected]:/var/www/python-forum.io/uploads /c/code
tester_V Wrote:It is the only way to start a python script on a remote PC is to use 'rpyc', there are no other 'modules' or some kind of a hack...
Python has many modules for this a couple mention bye Gribouillis.
Can also look into Fabric or Ansible.