Edit file through telnet possible?
-
Is it possible to edit files using Telnet?
-
It’s possible but very cumbersome, you’d have to do it using Python on the REPL.
Why not use FTP instead which is also available?
-
I have deployed some devices in the filed and have only enabled telnet instaead of telnet/ftp...how can i edit a file using REPL until i get access to them again.
-
@misterlisty How did you disable ftp, and can you enable it again though repl?
-
i forgot to open ftp port on the router on remote site.
-
@misterlisty
You might be able to upload a file in two steps
a) Upload a script which received data & puts it into a file:def newfile(path): print("Type file contents line by line, finish with EOF (Ctrl+D).") with open(path, "w") as f: while 1: try: l = input() except EOFError: break f.write(l) f.write("\n")Push Ctrl-E, paste the few lines about, and push Ctrl-D. Then you have the function newfile in RAM.
b) You can use that to upload another file. But that must be done slow. TeraTerm has an ASCII-Upload feature, which sends files line-by-line with an delay between the lines. You could use that to upload the changed files.I have an editor which works on the board. It is here: https://github.com/robert-hh/Micropython-Editor. I normally have it in flash. The editor is too large for devices w/o PSRAM to be executed from RAM. But you may be able to send your file the way sketched above.
Edit: Just tried my suggestion myself. Works not really well. Uploading the newfile() function works, but TeraTerm does not work well in an attempt to send that file, or the LoPy stalls, at least if it's more than a few lines of code.
-
@misterlisty I'm correcting my notes:
Used this little script for step a)import sys def getfile(path): print("Send file contents line by line, finish with Crl+C-Enter.") with open(path, "w") as f: while 1: try: l = sys.stdin.readline() except KeyboardInterrupt: break f.write(l) print(".", end="")It does not echo, but you have to end it with an error.
b) use the commandgetfile("name")
and then paste it from Teraterm (alt-v). In teraterm's special settings, use a long value for delay between lines for paste, like 100m. That way, I was able to upload a ~900 line python file (the editor). -
@misterlisty
I've had great success using the MicroPython rshell tool from https://github.com/dhylands/rshell over telnetAfter running rshell just do:
connect telnet your IP address
and you should then see the LoPy filesystem on /flash
Note that you the board must be in the REPL, if it's running a script you must terminate it
-
@jmarcelino Oh yes, I forgot the connect command of rshell. You can also edit through that tool, with
edit filename
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login