Python Forum
Copying files from a remote Windows station
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copying files from a remote Windows station
#1
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.
Reply
#2
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.
Reply
#3
(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.
Reply
#4
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.
Reply
#5
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'}
Reply
#6
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.
tester_V likes this post
Reply
#7
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.
Reply
#8
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.
tester_V likes this post
Reply
#9
Thank you! Great help!
Reply
#10
(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.
tester_V likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 359 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Rename files in a folder named using windows explorer hitoxman 3 731 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  Phyton Opening files on windows C: pc EddieG 3 976 Mar-29-2023, 03:19 PM
Last Post: buran
  Copying files if the name is in range tester_V 9 1,522 Nov-24-2022, 12:21 AM
Last Post: tester_V
  How to take the tar backup files form remote server to local server sivareddy 0 1,891 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Mathematical Conversion Scripts for Weather Station Mickey53usa 11 4,557 Jun-24-2020, 03:14 AM
Last Post: buran
  Copying a file Kundan 1 2,077 Aug-21-2019, 09:55 AM
Last Post: snippsat
  Help copying files with shutil hikerguy62 2 4,268 Aug-02-2019, 08:16 PM
Last Post: hikerguy62
  Code works in IDLE, appears to work in CMD, but won't produce files in CMD/Windows ChrisPy33 3 3,225 Jun-12-2019, 05:56 AM
Last Post: ChrisPy33
  help need with running python script on remote windows machine onenessboy 2 11,086 Dec-14-2018, 03:02 PM
Last Post: onenessboy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020