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.