Python Forum
Connecting to Remote Server to read contents of a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connecting to Remote Server to read contents of a file
#1
I want to get files which are kept on a remote server and can be connected using RDP. however, the port opened is 3389 instead of default port 22. Which is the best way to connect to the remote server and read the file on the desktop? I have used python library pyautogui, and it doesnt work.
Reply
#2
I don't know what RDP is.

The best tool ever for backing up files over the local network, or fetching files from a remote server is rsync.

To use rsync you need ssh installed and working on your laptop and server. There are lots of tutorials about setting up ssh available. You will need an ssh key on your computer and a copy of that on the remote server.

Then, just run a bash script to fetch the files using rsync.

A bash script is not Python!

Your computer must know where to find the bash script, or you will have to navigate to the folder and then run ./fetch_files.sh

I put all bash scripts in a folder called myBashScripts. Save the bash script, a simple text file, as fetch_messages.sh or whatever.

If you use Windows, I don't know how to set up such a script, but I presume it should also work

Quote:# save this as, for example, fetch_files.sh and make it executable
# get files from my little rented cloud server to my laptop
echo "Fetching any messages ... "
user="pedro"
# use your ip, of course
server="123.123.123.123"
# where to put the files on your laptop
Answers="/home/pedro/messages"
# where the uploaded contact messages go on the cloud server
path1="/var/www/mycloud.com/public_html/contact/messages"
echo "Getting the files from the remote server to this computer."
# set the login port for ssh if it is not 22, like: -p 3389
# this: --remove-source-files does what it says and removes the files on the cloud after fetching them.
rsync -av --remove-source-files --progress -e 'ssh -p 22 -i ~/.ssh/my_cloud_ed25519' $user@$server:${path1}/* "${Answers}"
echo "Got the files and saved them to "$Answers
echo "All done!"

The above is just a simple text file, write it in any simple text editor.

Run the bash script from a terminal. Fast and simple!

You can set up rsync as a daemon, then you don't need to call it specifically. I have never done that.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python is unable to read file Genericgamemaker 13 567 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 567 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 3,230 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 2,014 Nov-09-2023, 10:56 AM
Last Post: mg24
  read file txt on my pc to telegram bot api Tupa 0 1,374 Jul-06-2023, 01:52 AM
Last Post: Tupa
  Timestamp of file changes if a share mapped to a server…. tester_V 34 5,089 Jul-04-2023, 05:19 AM
Last Post: tester_V
  parse/read from file seperated by dots giovanne 5 1,376 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,807 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 8,949 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read csv file with inconsistent delimiter gracenz 2 1,451 Mar-27-2023, 08:59 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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