Editorial Workflows

FTP Upload

unlisted 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: ::: Processes the currently open text file in Editorial

::: Uploads the contents of the text file to an FTP host. Overwrites any existing file with the same path and name. Will request and store your user name and password on first run.

::: Must edit the the following variables in the Python script with your own connection details >> remotePath, host, port

Shared by: http://www.macdrifter.com/2013/08/ftp-upload-with-editorial.html

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Get Current File Name ?
Include Folder
Include Extension
Set Variable ?
Variable Name
Run Python Script ?
Source Code
import workflow
import editor
import ftplib
import console
import StringIO
import keychain
import pickle
import cgi

# Uncomment this line to reset stored password
#keychain.delete_password('macdrifter', 'editorial')
login = keychain.get_password('macdrifter', 'editorial')
if login is not None:
	user, pw = pickle.loads(login)
	user, pw = console.login_alert('FTPS Login Needed', 'No login credentials found.')
	pickle_token = pickle.dumps((user, pw))
	keychain.set_password('macdrifter', 'editorial', pickle_token)


remotePath = "/home/my/full/path/"
host = "hostname.com"
port = 22

docTitle = workflow.get_variable('postTitleVar')
fileName = docTitle+'.md'
confirmation = console.alert('Confirm', 'Go ahead and post?','Yes','No')

postContent = editor.get_text()

# Text encoidng sucks!
encode_string = cgi.escape(postContent).encode('ascii', 'xmlcharrefreplace')
#postContent.encode('ascii', 'replace')

buffer = StringIO.StringIO(encode_string)

	ftp = ftplib.FTP(host, user, pw)	
	ftp.storbinary('STOR '+ fileName, buffer)
except Exception, e:
	print e
	console.alert('Error', e)

action_in = workflow.get_input()
console.hud_alert('Posted '+fileName, 'success')

# Extension point to do something after the file is uploaded
action_out = action_in