How to upload to an FTP site

1,125 views
Skip to first unread message

Nick Brooks

unread,
Jul 31, 2013, 8:18:15 AM7/31/13
to tas...@googlegroups.com
Hi, this is my first post here so I hope it's useful.

I've been playing with an anti-theft set-up using Tasker and wanted to upload a picture to an FTP site.  I've managed to do it using SL4A and this Python script.  I'm a complete novice programmer so it may not work for you, but it does work for me.

You need to pass 6 variables from Tasker to SL4A - all are compulsory

%myFTPuser -           your user name on the FTP site
%myFPTpass -          your password
%myFTPserver -         the name of your ftp server (mine is ftp.zen.co.uk)
%myFTPremotedir -   the name of the directory on the remote system where you want to put the file (may need to exist first)
%myFTPremotefile -   the name of the file on the remote system (overwrites without asking)
%myFTPlocaldir -       the name of the directory where the file you want to upload is. (eg /sdcard/DCIM/Tasker)
%myFTPlocalfile -       The name of the local file (eg picture2.jpg)

The script doesn't do much error checking but will report missing variables and a success or fail at the end.


Here's the content of the script:-

import android
droid = android.Android()
from ftplib import FTP 
#
#check all variables are present
#
try:
    myFTPuser = droid.getIntent().result[u'extras'][u'%myFTPuser']
except:
    droid.makeToast('User name missing')
    exit(1)
try:
    myFTPpass = droid.getIntent().result[u'extras'][u'%myFTPpass']
except:
    droid.makeToast('Password missing')
    exit(1)
try:
    myFTPserver = droid.getIntent().result[u'extras'][u'%myFTPserver']
except:
    droid.makeToast('Server name missing')
    exit(1)
  
try:
    myFTPlocaldir = droid.getIntent().result[u'extras'][u'%myFTPlocaldir']
except:
    droid.makeToast('Local directory name missing')
    exit(1)
try:
    myFTPlocalfile = droid.getIntent().result[u'extras'][u'%myFTPlocalfile']
except:
    droid.makeToast('Local file name missing')
    exit(1)
try:
    myFTPremotedir = droid.getIntent().result[u'extras'][u'%myFTPremotedir']
except:
    droid.makeToast('Remote directory name missing')
    exit(1)
try:
    myFTPremotefile = droid.getIntent().result[u'extras'][u'%myFTPremotefile']
except:
    droid.makeToast('Remote file name missing')
    exit(1)
#
# Get full local path name
#

if myFTPlocaldir.endswith("/") is not True:
    myFTPlocaldir += "/"

myFTPlocalfilename = myFTPlocaldir + myFTPlocalfile

#
# Upload the file
#
try:  
    session = FTP(myFTPserver, myFTPuser, myFTPpass)
    session.cwd(myFTPremotedir)

    uploadfile = open(myFTPlocalfilename,'rb')                        
    session.storbinary('STOR ' + myFTPremotefile, uploadfile)
    droid.makeToast("Uploading now...")

    uploadfile.close()                                         
    session.quit() 
    droid.makeToast("File transfered")
except: 
    droid.makeToast("An error occured")


Konstantin Mozhukhov

unread,
Jul 31, 2013, 10:00:47 AM7/31/13
to tas...@googlegroups.com


2013/7/31 Nick Brooks <nick...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
с наилучшими пожеланиями,
     Константин Можухов
--

Brandon Horwath

unread,
Jul 31, 2013, 2:24:49 PM7/31/13
to tas...@googlegroups.com
I assume maybe this can be adapted to work with more than photos?

The real question, could this be adapted to get tasker to integrate with chromecast?!?

Hmmm?

Brandon Horwath

unread,
Jul 31, 2013, 7:45:49 PM7/31/13
to tas...@googlegroups.com
Nevermind. Koush made an app for this.

... but not as a tasker plug-in.

Wietse van Buitenen

unread,
Aug 1, 2013, 2:00:24 PM8/1/13
to tas...@googlegroups.com
thanks for sharing!
Reply all
Reply to author
Forward
0 new messages