Python Forum
RemoTe server operation with Paramiko issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RemoTe server operation with Paramiko issue
#1
Hi all,

I'm trying to learn about capabilities of Python to work on remote servers. For my setup I have local ServerA and remote ServerB, I need to run py on ServerB to get some output files. There is no any option to do it from anywhere else as it custom setup for security purposes, I only can run it from ServerB. They both are W boxes. Server B is totally isolated from network.

But for control and scheduling purposes I would like to operate on local ServerA. And for first step I tried to work with Paramiko to fire ServerB.test.py
And I'm getting error like below, I suspect it could be due the fact that I have very uncommon syntax for my account with backslash?

# Server connection details
hostname = 'xServerB'
username = 'rdc\\twil100'  # added extra \ for escape, original only single \
password = 'pswd123'   

try:
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname, username=username, password=password) # error here
    
	command = 'print(\'ServerB\')
    stdin, stdout, stderr = client.exec_command(command)

except Exception as e:
    print('Exc 3')
    print(f"An unexpected error occurred: {e}")	
	
####################
An unexpected error occurred: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
it takes more then 5 sec to get this error, so I assume it's just timeout. I tried to work with login name with and without escape \, no differences, even with bad password output is the same. I't failing on client.connect step.

Appreciate your help, excited to learn python and make my first post.
Best
Mario
Reply
#2
Don't know what a W box is, enlighten me please.

Quote:Server B is totally isolated from network.

You can't reach a computer that is totally isolated from the network. That is the point of isolating it!

But if it is not isolated from the network, after setting up SSH, use sftp to fetch the files you want. Much easier!

Enter sftp in a terminal on your local machine:

Quote:sftp user@123.456.789.123

The server will respond by asking you for your password:

Quote:user@123.456.789.123's password:

and if you enter the password correctly, you will receive a "you're connected" message, and the sftp prompt, like this:

Quote:Connected to server.myhost.com.
sftp>

Now you can look around, upload, download, even use a batch file to do what you want, as long as user has the correct permissions for the directories and files you are interested in.

sftp get command gets the remote_directory and stores it in local_directory

Specifically, when you have the sftp prompt in your terminal:

Quote:get -r remote_directory local_directory

And if you are fed up using a terminal, use Filezilla, Fillezilla is a frontend for sftp.
Reply
#3
Thanks Pedro and all, digesting all comments.
W = Windows , server running Windows.
Right now I don't have any problem remote to ServerB with user:password and do my things. So this server is on network, sorry I made a mistake in original posting saying it's isolated from any network.

Goal to setup unattended process on daily or so schedule, so I need to put everything into file.py

No matter what, for good start I still want to troubleshoot and make my Paramiko working.
Can anybody advice how you deal with username having back slash? Right now typing dummy password produces same result so it's not working, howevery that user:password allow me to connect vie remote connection.

Best
M
Reply
#4
If this rdc\twil100 is the password, then use raw-string-literals:

username = r"rdc\twil100"
The only character you must pay attention is the quote (' if used or "). If it's closed and the previous character is a backslash, then this must be escaped.

Example: foo\

print(r"foo\\")
The last character \ must be escaped to prevent escaping the end of the quote.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
Thanks DE! tried, it's same, also tried bad password and got the same error.
Just learned a simple test to test SSH, doing it from cmd
>>ssh\twil100@xServerB
expecting prompt for password, but it never happened.

So should be some tricks with port forwarding. SSH is enabled on both boxes (>>>ssh produces output).
ping to box works, but telnet does NOT, tried pretty much all open ports.

Assume that it's not about paramiko but about networking.
Reply
#6
tested everything, Paramiko doesn't work in modern situations where security is set properly.
Reply
#7
(Jul-03-2025, 11:08 PM)mario17 Wrote: it takes more then 5 sec to get this error, so I assume it's just timeout. I tried to work with login name with and without escape \, no differences, even with bad password output is the same. I't failing on client.connect step.
It isn’t your backslash-escaping that’s causing this WinError 10060 – that error is a straight TCP timeout.
On Windows, unless you’ve explicitly installed and enabled an SSH server, port 22 will be closed and unreachable,
so then client.connect() will hang until it times out.

Test on a open sever here from comman line(i use cmder here which has ssh build in).
password: password
E:\div_code\paramiko_test (master)
λ ssh -p 22 [email protected]
Welcome to test.rebex.net! See https://test.rebex.net/ for more information.
([email protected]) Password:
For a list of supported commands, type 'help'.
demo@test:/$ ls
pub
readme.txt
demo@test:/$
Paramiko test:
# para_test.py
import paramiko

hostname = 'test.rebex.net'
port     = 22
username = 'demo'
password = 'password'

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
    hostname,
    port=port,
    username=username,
    password=password,
    look_for_keys=False,
    allow_agent=False,
    timeout=10
)

stdin, stdout, stderr = client.exec_command('uname -a')
print('STDOUT:', stdout.read().decode().strip())

stdin, stdout, stderr = client.exec_command('ls -l /')
print(stdout.read().decode())

client.close()
Output:
STDOUT: Rebex Virtual Shell drwx------ 2 demo users 0 Mar 31 2023 . drwx------ 2 demo users 0 Mar 31 2023 .. drwx------ 2 demo users 0 Mar 31 2023 pub -rw------- 1 demo users 379 Sep 19 2023 readme.txt
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running script from remote to server invisiblemind 4 1,837 Mar-28-2025, 07:57 AM
Last Post: buran
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 4,841 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 1,592 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  How to take the tar backup files form remote server to local server sivareddy 0 3,241 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  run a health check script on cloud server through paramiko amritjsr 4 5,744 Jul-21-2020, 02:30 AM
Last Post: amritjsr
  python3 emulate tail -f on remote server... support required anna 0 2,782 Jul-01-2020, 06:42 AM
Last Post: anna
  Unable to login to remote SQL Server database sipriusPT 1 17,806 Dec-20-2019, 10:16 AM
Last Post: sipriusPT
  Paramiko output printing issue anna 3 19,112 Feb-06-2018, 08:34 AM
Last Post: anna
  Take one parameter which is an URL to a remote server ciaranacrowley 1 4,347 Oct-15-2017, 07:44 PM
Last Post: buran

Forum Jump:

User Panel Messages

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