Python Forum
Running script from remote to server
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running script from remote to server
#1
I had a request to help with the process of transferring scanned records from one folder to another and creating subfolders for new records. I was able to get the code working locally on my computer, but it wouldn't work when I sent it to the end user. Would this work running from a client to the server, or does it need to be run on the server? The source and destination were updated to Z drive info for their server.

import os import shutil from datetime import datetime import tkinter as tk from tkinter import messagebox # Source and destination directories source_dir = r'C:\Users\justi\OneDrive\Desktop\scanned' destination_dir = r'F:\scanned' # Function to transfer documents and generate a report def transfer_documents(): # Variables to track the number of files and folders files_transferred = 0 new_folders_created = 0 # Loop through all files in the source directory for filename in os.listdir(source_dir): # Skip directories and process all files regardless of extension if os.path.isfile(os.path.join(source_dir, filename)): # Split the filename to get first name, last name, and date of birth name_parts = filename name_without_extension, _ = os.path.splitext(name_parts) # Remove file extension parts = name_without_extension.split(',') if len(parts) >= 3: # We expect at least three parts: first name, last name, and date of birth first_name = parts[0].strip() last_name = parts[1].strip() dob = parts[2].strip() # Verify that the date of birth is in a valid format (MM-DD-YYYY) try: # Check if the date format is valid datetime.strptime(dob, "%m-%d-%Y") # Construct the folder name based on first name, last name, and date of birth folder_name = f"{first_name}, {last_name}, {dob}" destination_folder = os.path.join(destination_dir, folder_name) # Create the folder in the destination directory if it doesn't exist if not os.path.exists(destination_folder): os.makedirs(destination_folder) new_folders_created += 1 # Construct the full path to the file source_file_path = os.path.join(source_dir, filename) destination_file_path = os.path.join(destination_folder, filename) # Move the file to the new folder shutil.move(source_file_path, destination_file_path) files_transferred += 1 except ValueError: print(f"Skipping {filename}: Invalid date format for date of birth.") # Create a completion report inside the destination directory report_file_path = os.path.join(destination_dir, 'transfer_report.txt') with open(report_file_path, 'w') as report: report.write(f"Transfer Report - {datetime.now()}\n") report.write("="*50 + "\n") report.write(f"Total files transferred: {files_transferred}\n") report.write(f"New folders created: {new_folders_created}\n") report.write("="*50 + "\n") # Popup completion message root = tk.Tk() root.withdraw() # Hide the main window messagebox.showinfo( "Transfer Complete", f"Transfer complete. {files_transferred} files were transferred.\n" f"{new_folders_created} new folders were created.\n" f"Completion report generated at: {report_file_path}" ) root.destroy() # Run the function if __name__ == '__main__': transfer_documents()
Reply
#2
Questions:
  1. What error is end user getting? (ask for complete unaltered traceback, and post here)
  2. You have hard coded paths in your code, Is the directory structure the same on end users computer?
Gribouillis likes this post
Reply
#3
(Mar-27-2025, 02:03 PM)Larz60+ Wrote: Questions:
  1. What error is end user getting? (ask for complete unaltered traceback, and post here)
  2. You have hard coded paths in your code, Is the directory structure the same on end users computer?

The source and destination were updated on the end user's side. When they run the script, they just get a temporary window popup.
I have never run a script from a client to a server, so I'm unsure if there is anything different I should have done or if it would be easier if they ran this script from the server itself. I am only able to do support over the phone with them and walked them thru the best I could to replace the pathways. Example of the path they put in (source_dir = r'Z:\scanned').
Reply
#4
my guess, without seeing specific error is that their paths were entered incorrectly.
buran likes this post
Reply
#5
(Mar-27-2025, 02:19 PM)invisiblemind Wrote: When they run the script, they just get a temporary window popup.
Most likely they have .py files associated with python and run it with double click. Ask them to run it from command line/shell and get the output.
It's just fine to run it on one machine and process files on network drive/server.

Given it's a CLI I wouldn't use tkinter just for a pop-up message box.
You can use loguru (https://github.com/Delgan/loguru) to easily create log/output progress info.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  RemoTe server operation with Paramiko issue mario17 6 1,701 Jul-14-2025, 10:14 AM
Last Post: snippsat
  Detect if another copy of a script is running from within the script gw1500se 4 2,033 Jan-31-2025, 11:30 PM
Last Post: Skaperen
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 4,727 May-03-2024, 07:23 AM
Last Post: Pedroski55
  No Internet connection when running a Python script basil_555 8 5,081 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 13,723 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 1,546 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Help Running Python Script in Mac OS emojistickers 0 1,338 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  Trying to make a board with turtle, nothing happens when running script Quascia 3 2,502 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Python script running under windows over nssm.exe JaroslavZ 0 3,378 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Running script with subprocess in another directory paul18fr 1 17,675 Jan-20-2023, 02:33 PM
Last Post: paul18fr

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.