1
Hello;
I’m trying to make a python script to connect to port 12612 localhost. Running the telnet command on linux, manually, it runs. However, in my python script, using the telnetlib library, it is apparently not connecting. I need to connect to the telnet console, and perform some tasks. Follow the code:
import os, glob, telnetlib, time
CAMINHO = "/home/admin/deploy"
HOST = "localhost"
PORT = "12612"
TIMEOUT = 2
filename = os.path.basename(__file__)
os.chdir(CAMINHO)
try:
tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
tn.set_debuglevel('DEBUG')
tn.open(HOST, PORT, TIMEOUT)
except ValueError:
print("Falha ao conectar")
for file in glob.glob("*.jar"):
arquivoAtual = file.split('_')[0]
comando = ("file://" + CAMINHO + "/" + file).strip()
tn.write(("uninstall " + arquivoAtual + "\n"))
tn.write("install " + comando + "\n")
tn.write("setbsl 5" + arquivoAtual + "\n")
tn.write("start " + arquivoAtual + "\n")
tn.write("exit" + "\n")
tn.close()
print('Concluido')
"apparently not connecting" as so, what happens? you get some kind of error?
– nosklo
No error, but also, commands are not executed.
– Éder Pereira
Do you get the "Failed to connect" message? And the "Done" message at the end?
– nosklo
I placed after the for a Tn.read_all(), and now gives the following error: python deploy.py Traceback (Most recent call last): File "deploy.py", line 32, in <module> Tn.read_all() File "/usr/lib/python2.7/telnetlib.py", line 385, in read_all self.fill_rawq() File "/usr/lib/python2.7/telnetlib.py", line 576, in fill_rawq buf = self.sock.recv(50) socket.timeout: timed out The completed message appears if I take out Tn.read_all().
– Éder Pereira
Maybe he’s not getting into
for
- are sure you have files.jar
in the current directory? Put aprint(file)
within thefor
to make sure that commands are being sent– nosklo
Yes, the files are in the directory, I had already tested it ( with a print ). It’s quite strange this, I read in a place that, the library was made to work on port 23 with self negotiation. Any different port, which does not have auto-negotiation, may happen that the library cannot interact with the ftp server. ftp in question is idempiere’s osgi console. I’m making a script to update new application plugins with python.
– Éder Pereira
Opa, Peraí, you said the server is FTP?? I thought it was telnet!! To access ftp servers, you must use the module
ftplib
and nottelnetlib
.– nosklo
guy, sorry. It is telnet yes, only at door 12612.
– Éder Pereira