Based on omz/FileTransfer.py. Get Pythonista for iOS here: Pythonista.
This script attempts to make transferring files to and from Pythonista a little bit more secure by using SSL, and Basic authentication.
Use at your own risk...
You will need an SSL self signed certificate before you start. There are a bunch of posts on the web on how to do this already. Just looks around. :-)
- Get this script
PythonistaFileServer.py
onto your Pythonista installation. - Run
PythonistaFileServer.py
. This first attempt will fail. RunningPythonistaFileServer.py
will make the module available in the console, which is needed for the next step. - Go to the Pythonista console and:
That will create the
>>> import PythonistaFileServer >>> PythonistaFileServer.init_config()
~/Documents/.httpfileserver
directory, and initialize theconfig.cfg
file in there. - Swipe right to go back to the editor, you should see
~/Documents/.httpfileserver/config.cfg
. Make sure to fill in theusername
, andpassword
. - Upload your
server.key
, andserver.crt
files into the~/Documents/.httpfileserver
directory. - Start up PythonistaFileServer. You should be good to go.
- From within Pythonista, run
PythonistaFileServer
, then quit. This will makePythonistaFileServer
available for import. - Swipe left to get the console, and
>>> import PythonistaFileServer >>> PythonistaFileServer.edit_config()
- Swipe right to bring up the editor then make your changes.
The following examples assumes a username of test
, and password of
tester
. Pick something more secure.
To the document root:
$ curl --insecure --user "test:tester" "https://testserver.local:8843/"
{
"cwd": "/",
"files": [
"PythonistaFileServer.py",
"Welcome.txt",
"test1/Welcome.txt"
],
"status": {
"message": "success",
"type": "success"
}
}
To sub directories:
$ curl --insecure --user "test:tester" "https://testserver.local:8843/test1"
{
"cwd": "/test1",
"files": [
"test1/Welcome.txt"
],
"status": {
"message": "success",
"type": "success"
}
}
To the document root:
$ curl --insecure --user "test:tester" -F "[email protected]" \
"https://testserver.local:8843/"
{
"cwd": "/",
"files": [
"PythonistaFileServer.py",
"somescript.py",
"Welcome.txt",
"test1/Welcome.txt"
],
"status": {
"message": "success",
"type": "success"
}
}
To a sub directory:
$ curl --insecure --user "test:tester" -F "[email protected]" \
"https://testserver.local:8843/test1"
Uploading and excluding the files
section, set the short
query parameter to
true
:
$ curl --insecure --user "test:tester" -F "[email protected]" \
"https://testserver.local:8843/test1?short=true"
{
"cwd": "/test1",
"status": {
"message": "somescript.txt uploaded (renamed to somescript-3.txt).",
"type": "success"
}
}
Set the overwrite
query parameter to true
:
$ curl --insecure --user "test:tester" -F "[email protected]" \
"https://testserver.local:8843/test1?short=true&overwrite=true"
- 0.0.0
- Minor whitespace cleanup.
- Added HTTP Basic Authentication. Thanks to StackOverflow - Stuck with Python HTTP Server with Basic Authentication using BaseHTTP.
- SSL support.
- Configuration file.
- RESTish type interface with JSON output.
- URL path validation.
- And much more...