Editorial Workflows

Download Recent From SFTP

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Connects to a remote SFTP host and displays a list of the 20 most recently modified documents. Select one from the list to download to the Editorial local file storage.

:::Only downloads TXT and MD files.:::

:::Overwrites local file with the same name as remote file unless the local file is open in the editor:::

:::Stores SFTP login credentials in the Editorial keychain.:::

:::Must modify two scripts with remote host connection and path details:::

Made by Macdrifter.com

Shared by: http://www.macdrifter.com/2013/08/editorial-sftp-workflows.html

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
import workflow
import console
import keychain
import pickle
import paramiko


#keychain.delete_password('macdrifter', 'editorial')
login = keychain.get_password('macdrifter_ssh', 'editorial')
if login is not None:
	user, pw = pickle.loads(login)
else:
	user, pw = console.login_alert('FTPS Login Needed', 'No login credentials found.')
	pickle_token = pickle.dumps((user, pw))
	keychain.set_password('macdrifter_ssh', 'editorial', pickle_token)


remote_path = "/your/remote/file/path/"
host = "some.host.com"
port = 22

try:
	client = paramiko.SSHClient()
	client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
	client.connect(host, port=port, username=user, password=pw)
	stdin, stdout, stderr = client.exec_command('cd '+remote_path+';ls -t | head -20')
	
	action_out = stdout.read()
	workflow.set_output(action_out)

except Exception, e:
	print e
	console.alert('Error', e)
finally: 
	client.close()
Select from List ?
Title
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Set Variable ?
Variable Name
fileName
Value
Input
Run Python Script ?
Source Code
import workflow
import editor
import console
import urllib
import keychain
import pickle
import paramiko
import os
import webbrowser

#keychain.delete_password('macdrifter', 'editorial')
login = keychain.get_password('macdrifter_ssh', 'editorial')
if login is not None:
	user, pw = pickle.loads(login)
else:
	user, pw = console.login_alert('FTPS Login Needed', 'No login credentials found.')
	pickle_token = pickle.dumps((user, pw))
	keychain.set_password('macdrifter_ssh', 'editorial', pickle_token)

remote_path = "/the/same/path/as/previous/script/"
host = "samehost.asbefore.com"
port = 22
local_path = os.path.expanduser('~/Documents')
file_name = workflow.get_variable('fileName')

ext = os.path.splitext(file_name)[1]
if ext != '.txt' and ext != '.md':
	console.alert('Incorrect File Type', 'Editorial can only download TXT and MD file types')


try:

	transport = paramiko.Transport((host, port))
	transport.connect(username=user, password=pw)
	sftp = paramiko.SFTPClient.from_transport(transport)
	sftp.get(remote_path+file_name, local_path+'/'+file_name)

	sftp.close()
	transport.close()
	webbrowser.open('editorial://open/'+urllib.quote(file_name))

except Exception, e:
	print e
	console.alert('Error', e)