def upload(self, screenshot, name): self.loadSettings() #Save to a temporary file timestamp = time.time() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Connect to server transport = paramiko.Transport((self.host, self.port)) if self.authMethod == "Password": try: transport.connect(username = self.username, password = self.password) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (password)") return False else: try: private_key = paramiko.RSAKey.from_private_key_file(self.keyfile, password=self.passphrase) transport.connect(username=self.username, pkey=private_key) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (key)") return False sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name)) except IOError: ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.") return False sftp.close() transport.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True
def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) ftp = ftplib.FTP() ftp.connect(self.host, self.port) ftp.login(self.username, self.password) f = open(tmpFilename, 'rb') try: ftp.cwd(self.folder) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False try: ftp.storbinary('STOR ' + name, f) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False ftp.quit() f.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True
def upload(self, screenshot, name): self.loadSettings() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s = tmpFilename)) try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: p = subprocess.Popen(command.split()) p.wait() if p.returncode > 0: ScreenCloud.setError("Command " + command + " did not return 0") return False except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
def upload(self, screenshot, name): self.loadSettings() #Make sure we have a up to date token if not self.uploadAnon: try: self.imgur.refresh_access_token() except Exception as e: ScreenCloud.setError("Failed to refresh imgur access token. " + e.message) return False #Save to a temporary file timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Upload! try: uploaded_image = self.imgur.upload_image(tmpFilename, title=ScreenCloud.formatFilename(name, False)) except Exception as e: ScreenCloud.setError("Failed to upload to imgur. " + e.message) return False if self.copyLink: if self.copyDirectLink: ScreenCloud.setUrl(uploaded_image.link) else: ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id) return True
def browseForKeyfile(self): filename = QFileDialog.getOpenFileName( self.settingsDialog, "Select Keyfile...", QDesktopServices.storageLocation(QDesktopServices.HomeLocation), "*", ) if filename: self.settingsDialog.group_server.input_keyfile.setText(filename)
def upload(self, screenshot, name): self.loadSettings() # Save to a temporary file timestamp = time.time() try: tmpFilename = ( QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) ) except AttributeError: from PythonQt.QtCore import QStandardPaths # fix for Qt5 tmpFilename = ( QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) ) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) # Connect to server try: transport = paramiko.Transport((self.host, self.port)) except Exception as e: ScreenCloud.setError(e.message) return False if self.authMethod == "Password": try: transport.connect(username=self.username, password=self.password) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (password)") return False else: try: private_key = paramiko.RSAKey.from_private_key_file(self.keyfile, password=self.passphrase) transport.connect(username=self.username, pkey=private_key) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (key)") return False except paramiko.SSHException as e: ScreenCloud.setError("Error while connecting to " + self.host + ":" + str(self.port) + ". " + e.message) return False except Exception as e: ScreenCloud.setError("Unknown error: " + e.message) return False sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name)) except IOError: ScreenCloud.setError( "Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions." ) return False sftp.close() transport.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True
def __init__(self): paramiko.util.log_to_file(QDesktopServices.storageLocation(QDesktopServices.HomeLocation) + "/screencloud-sftp.log") uil = QUiLoader() self.settingsDialog = uil.load(QFile(workingDir + "/settings.ui")) self.settingsDialog.group_server.combo_auth.connect("currentIndexChanged(QString)", self.authMethodChanged) self.settingsDialog.group_server.button_browse.connect("clicked()", self.browseForKeyfile) self.settingsDialog.group_location.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.loadSettings() self.updateUi()
def __init__(self): try: tempLocation = QDesktopServices.storageLocation(QDesktopServices.TempLocation) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tempLocation = QStandardPaths.writableLocation(QStandardPaths.TempLocation) paramiko.util.log_to_file(tempLocation + "/screencloud-sftp.log") self.uil = QUiLoader() self.loadSettings()
def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) f = open(tmpFilename, 'rb') response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f) f.close() os.remove(tmpFilename) if self.copy_link: share = self.client.share('/' + ScreenCloud.formatFilename(name)) ScreenCloud.setUrl(share['url']) return True
def upload(self, screenshot, name): temp = QDesktopServices.storageLocation(QDesktopServices.TempLocation) file = temp + '/' + name screenshot.save(QFile(file), ScreenCloud.getScreenshotFormat()) ns = NoelShack() try: url = ns.upload(file) except NoelShackError as e: ScreenCloud.setError(str(e)) return False ScreenCloud.setUrl(url) return True
def upload(self, screenshot, name): temp = QDesktopServices.storageLocation(QDesktopServices.TempLocation) file = temp + '/' + name screenshot.save(QFile(file), ScreenCloud.getScreenshotFormat()) register_openers() datagen, headers = multipart_encode({'file': open(file, 'rb')}) req = urllib2.Request('https://vgy.me:443/upload', datagen, headers) res = json.loads(urllib2.urlopen(req).read()) ScreenCloud.setUrl(res['url']) return True
def upload(self, screenshot, name): self.loadSettings() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(time.time())) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) data = {"name": name} files = {"file": open(tmpFilename, "rb")} try: response = requests.post("http://uguu.se/api.php?d=upload-tool", data=data, files=files) response.raise_for_status() if self.copyLink: ScreenCloud.setUrl(response.text) except RequestException as e: ScreenCloud.setError("Failed to upload to Uguu.se: " + e.message) return False return True
def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename( str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) f = open(tmpFilename, 'rb') response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f) f.close() os.remove(tmpFilename) if self.copy_link: share = self.client.share('/' + ScreenCloud.formatFilename(name)) ScreenCloud.setUrl(share['url']) return True
def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) f = open(tmpFilename, 'rb') response = self.client.files_upload(f, '/' + ScreenCloud.formatFilename(name)) f.close() os.remove(tmpFilename) if self.copy_link: share = self.client.sharing_create_shared_link('/' + ScreenCloud.formatFilename(name), short_url=True) ScreenCloud.setUrl(share.url) return True
def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) f = open(tmpFilename, 'rb') response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f) f.close() os.remove(tmpFilename) if self.copy_link: share = self.client.share('/' + ScreenCloud.formatFilename(name)) ScreenCloud.setUrl(share['url']) return True
def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) f = open(tmpFilename, 'rb') response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f) f.close() os.remove(tmpFilename) if self.copy_link: share = self.client.share('/' + ScreenCloud.formatFilename(name), False) ScreenCloud.setUrl(share['url'].replace('dl=0', 'raw=1')) return True
def upload(self, screenshot, name): self.loadSettings() try: tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + name except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s=tmpFilename)) try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: if self.outputIsUrl: pipe = subprocess.PIPE else: pipe = None p = subprocess.Popen(command, shell=True, stdout=pipe) p.wait() if p.returncode > 0: ScreenCloud.setError( "Command %s returned %d, but 0 was expected" % (str(command), int(p.returncode))) return False elif self.outputIsUrl: result = bytes.decode(p.stdout.read()) result = result.strip() ScreenCloud.setUrl(result) except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) try: oc = owncloud.Client(self.url) oc.login(self.username, self.password) remotePath = "" if self.remotePath: remotePath = self.remotePath try: oc.file_info(remotePath) except Exception: oc.mkdir(remotePath) uploaded_image = oc.put_file(remotePath + "/" + ScreenCloud.formatFilename(name, False), tmpFilename) if self.copyLink: link_info = oc.share_file_with_link(remotePath + "/" + ScreenCloud.formatFilename(name, False)) share_link = link_info.get_link() if self.copyDirectLink: share_link = share_link + "/download" ScreenCloud.setUrl(share_link) return True except Exception as e: ScreenCloud.setError("Failed to upload to OwnCloud. " + e.message) return False
def upload(self, screenshot, name): self.loadSettings() try: tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + name except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) base_path = os.path.dirname(os.path.realpath(__file__)) + '/' command = "bash " + base_path + "puush.sh " + self.apiKey + " " + tmpFilename try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: if self.outputIsUrl: pipe = subprocess.PIPE else: pipe = None p = subprocess.Popen(command, shell=True, stdout=pipe) p.wait() if p.returncode > 0: ScreenCloud.setError("Command " + command + " did not return 0") return False elif self.outputIsUrl: result = p.stdout.read() result = result.strip() ScreenCloud.setUrl(result) except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
def upload(self, screenshot, name): self.loadSettings() url = self.url_address if not url.startswith('http'): ScreenCloud.setError('Invalid url!') return False timestamp = time.time() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) reply = requests.post(url, files={'image': open(tmpFilename, 'rb')} ).json() try: ScreenCloud.setUrl(reply['href']) except Exception as e: ScreenCloud.setError("Could not upload to: " + self.url_address + "\nError: " + e.message) return False return True
def upload(self, screenshot, name): self.loadSettings() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s = tmpFilename)) try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: if self.outputIsUrl: pipe = subprocess.PIPE else: pipe = None p = subprocess.Popen(command, shell=True, stdout=pipe) p.wait() if p.returncode > 0: ScreenCloud.setError("Command %s returned %d, but 0 was expected" % (str(command), int(p.returncode))) return False elif self.outputIsUrl: result = bytes.decode(p.stdout.read()) result = result.strip() ScreenCloud.setUrl(result) except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
def upload(self, screenshot, name): self.loadSettings() #Make sure we have a up to date token if not self.uploadAnon: self.imgur.refresh_access_token() #Save to a temporary file timestamp = time.time() tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename( str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Upload! try: uploaded_image = self.imgur.upload_image( tmpFilename, title=ScreenCloud.formatFilename(name, False)) except Exception as e: ScreenCloud.setError("Failed to upload to imgur. " + e.message) return False if self.copyLink: if self.copyDirectLink: ScreenCloud.setUrl(uploaded_image.link) else: ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id) return True
def __init__(self): paramiko.util.log_to_file(QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/screencloud-sftp.log") self.uil = QUiLoader() self.loadSettings()
def __init__(self): paramiko.util.log_to_file( QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/screencloud-sftp.log") self.uil = QUiLoader() self.loadSettings()
def getPluginDir(): try: return QDesktopServices.storageLocation(QDesktopServices.DataLocation) + "/plugins" except AttributeError: from PythonQt.QtCore import QStandardPaths return QStandardPaths.writableLocation(QStandardPaths.DataLocation) + "/plugins"
def upload(self, screenshot, name): self.loadSettings() #Save to a temporary file timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Connect to server try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.host, self.port)) session = Session() session.handshake(sock) except Exception as e: ScreenCloud.setError(e.message) return False if self.authMethod == "Password": try: session.userauth_password(self.username, self.password) except ssh2.exceptions.AuthenticationError: ScreenCloud.setError("Authentication failed (password)") return False else: try: session.userauth_publickey_fromfile(self.username, self.keyfile, passphrase=self.passphrase) except ssh2.exceptions.AuthenticationError: ScreenCloud.setError("Authentication failed (key)") return False except Exception as e: ScreenCloud.setError("Unknown error: " + e.message) return False sftp = session.sftp_init() mode = LIBSSH2_SFTP_S_IRUSR | \ LIBSSH2_SFTP_S_IWUSR | \ LIBSSH2_SFTP_S_IRGRP | \ LIBSSH2_SFTP_S_IROTH f_flags = LIBSSH2_FXF_CREAT | LIBSSH2_FXF_WRITE try: try: sftp.opendir(self.folder) except ssh2.exceptions.SFTPError: sftp.mkdir(self.folder, mode | LIBSSH2_SFTP_S_IXUSR) (filepath, filename) = os.path.split(ScreenCloud.formatFilename(name)) if len(filepath): for folder in filepath.split("/"): try: sftp.mkdir(folder) except IOError: pass source = tmpFilename destination = self.folder + "/" + ScreenCloud.formatFilename(filename) with open(source, 'rb') as local_fh, sftp.open(destination, f_flags, mode) as remote_fh: for data in local_fh: remote_fh.write(data) except IOError: ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.") return False sock.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True
def browseForKeyfile(self): filename = QFileDialog.getOpenFileName(self.settingsDialog, "Select Keyfile...", QDesktopServices.storageLocation(QDesktopServices.HomeLocation), "*") if filename: self.settingsDialog.group_server.input_keyfile.setText(filename)
def upload(self, screenshot, name): self.loadSettings() f = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(name) screenshot.save(QFile(f), ScreenCloud.getScreenshotFormat()) now = datetime.datetime.now() date = "/%s/%02d/%02d" % (now.year, now.month, now.day) path = "/%s/%02d/%02d/%s" % (now.year, now.month, now.day, ScreenCloud.formatFilename(name)) if self.type == "SFTP": transport = paramiko.Transport((self.host, self.port)) transport.connect(username = self.username, password = self.password) sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.chdir(os.path.normpath(self.path) + date) except IOError: sftp.mkdir(os.path.normpath(self.path) + date) try: sftp.put(f, os.path.normpath(self.path) + path) except IOError: ScreenCloud.setError("Failed to write file") sftp.close() transport.close() elif self.type == "FTP": ftp = ftplib.FTP() ftp.connect(self.host, self.port) ftp.login(self.username, self.password) if os.path.normpath(self.path) in ftp.nlst(): try: ftp.cwd(os.path.normpath(self.path)) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False year = "%02d" % now.year month = "%02d" % now.month day = "%02d" % now.day if year in ftp.nlst(): ftp.cwd(year) else: ftp.mkd(year) ftp.cwd(year) if month in ftp.nlst(): ftp.cwd(month) else: ftp.mkd(month) ftp.cwd(month) if day in ftp.nlst(): ftp.cwd(day) else: ftp.mkd(day) ftp.cwd(day) #borrowed from screencloud ftp plugin fs = open(f, 'rb') try: ftp.storbinary('STOR ' + name, fs) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False ftp.quit() fs.close() url = "%s%s/%s/%s/%s" % (self.url, now.year, now.month, now.day, ScreenCloud.formatFilename(name)) ScreenCloud.setUrl(self.url.strip("/") + path) return True
def getPluginDir(): return QDesktopServices.storageLocation(QDesktopServices.DataLocation) + "/plugins"
def getPluginDir(): return QDesktopServices.storageLocation( QDesktopServices.DataLocation) + "/plugins"
def upload(self, screenshot, name): self.loadSettings() #Save to a temporary file timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Connect to server try: transport = paramiko.Transport((self.host, self.port)) except Exception as e: ScreenCloud.setError(e.message) return False if self.authMethod == "Password": try: transport.connect(username=self.username, password=self.password) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (password)") return False else: try: private_key = paramiko.RSAKey.from_private_key_file( self.keyfile, password=self.passphrase) transport.connect(username=self.username, pkey=private_key) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (key)") return False except paramiko.SSHException as e: ScreenCloud.setError("Error while connecting to " + self.host + ":" + str(self.port) + ". " + e.message) return False except Exception as e: ScreenCloud.setError("Unknown error: " + e.message) return False sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.chdir(self.folder) (filepath, filename) = os.path.split(ScreenCloud.formatFilename(name)) if len(filepath): for folder in filepath.split("/"): try: sftp.mkdir(folder) except IOError: pass sftp.chdir(folder) sftp.put(tmpFilename, ScreenCloud.formatFilename(filename)) except IOError: ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.") return False sftp.close() transport.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True