Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Edit file through telnet possible?

    Scheduled Pinned Locked Moved Discussion
    lopy
    9 Posts 3 Posters 2.1k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      misterlisty
      last edited by

      Is it possible to edit files using Telnet?

      1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino
        last edited by jmarcelino

        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?

        1 Reply Last reply Reply Quote 0
        • M Offline
          misterlisty
          last edited by

          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.

          robert-hhR J 2 Replies Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @misterlisty
            last edited by

            @misterlisty How did you disable ftp, and can you enable it again though repl?

            1 Reply Last reply Reply Quote 0
            • M Offline
              misterlisty
              last edited by

              i forgot to open ftp port on the router on remote site.

              robert-hhR 2 Replies Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @misterlisty
                last edited by robert-hh

                @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.

                1 Reply Last reply Reply Quote 1
                • robert-hhR Offline
                  robert-hh @misterlisty
                  last edited by

                  @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 command getfile("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).

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jmarcelino @misterlisty
                    last edited by jmarcelino

                    @misterlisty
                    I've had great success using the MicroPython rshell tool from https://github.com/dhylands/rshell over telnet

                    After 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

                    robert-hhR 1 Reply Last reply Reply Quote 1
                    • robert-hhR Offline
                      robert-hh @jmarcelino
                      last edited by

                      @jmarcelino Oh yes, I forgot the connect command of rshell. You can also edit through that tool, with
                      edit filename

                      1 Reply Last reply Reply Quote 1

                      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
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom