omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Uploading an image using SFTP (paramiko)

    Pythonista
    6
    9
    6574
    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.
    • sebietter
      sebietter last edited by

      I'm using paramiko to (successfully) connect to my server using SFTP. I tried to upload an image chosen via photos.pick_image() but can't get Pythonista to upload the image.

      My code:

      import paramiko
      import photos
      from io import BytesIO
      import urllib
      import datetime
      
      # SFTP Configuration
      
      host = 'MyHost'
      port = 22
      transport = paramiko.Transport((host, port))
      
      password = 'MyPassword"
      username = 'MyUsername'
      transport.connect(username = username, password = password)
      
      sftp = paramiko.SFTPClient.from_transport(transport)
      
      # Image & Link Setup
      
      today = datetime.datetime.now()
      image = photos.pick_image()
      print image
      fileName = 'ios'
      fileName = fileName + '_' + today.strftime("%Y-%m-%d-%H%M%S") + '.png'
      
      urlBase = 'myURL'
      encodedFileName = urllib.quote(fileName)
      print fileName
      
      remoteFilePath = 'MyPath'
      
      # Upload the image
      
      sftp.put(image, remoteFilePath + fileName)
      
      sftp.close()
      transport.close()
      print 'Upload done!'
      
      # Paste image link to clipboard
      
      clipboard.set(urlBase + encodedFileName)
      

      I'd be really grateful if one of you could explain me what I'm doing wrong and how I could solve my problem of not being able to upload an image.

      1 Reply Last reply Reply Quote 0
      • briarfox
        briarfox last edited by

        @sebietter I thought paramiko required pyCrypto which is compiled code.

        1 Reply Last reply Reply Quote 1
        • ihf
          ihf last edited by

          I don't know that I can help with your image upload problem but I was wondering if you could say what you did to get paramiko ported to Pythonista. I tried to merely run the setup.py but got an import error relating to module osx_support.

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            @ihf

            paramiko is included in Pythonista.

            1 Reply Last reply Reply Quote 0
            • briarfox
              briarfox last edited by

              @omz you just made my day. SSH client for Shellista here we come.

              1 Reply Last reply Reply Quote 0
              • ihf
                ihf last edited by

                import paramiko works though help(paramiko) does not. I got it to execute a remote shell cmd though other paramiko demos (e.g., demo_simple.py) will not run probably because of missing modules.

                1 Reply Last reply Reply Quote 0
                • sebietter
                  sebietter last edited by

                  I don't know if anybody is even interested but as a little follow up I'd like to quickly explain how I was able to solve the problem. I simply saved the image to my Pythonista library and uploaded it from there:

                  imgSaved = image.save(fileName)
                  

                  And then upload it using the sftp.put command:

                  sftp.put(fileName, remoteFilePath + fileName)
                  

                  With os.remove(fileName) the file can finally be removed from the Pythonista library to keep everything clean.

                  1 Reply Last reply Reply Quote 1
                  • nasadave
                    nasadave last edited by

                    Thanks for adding the follow up. I needed that.

                    1 Reply Last reply Reply Quote 1
                    • potato
                      potato last edited by

                      Thanks for the follow up, exactly what i needed

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors