Greetings to those that do not sleep!
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.
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.
(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.
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.
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'}
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.
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.
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.
(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.