The script works fine with the 'put' argument. I can easily receive files on the Raspberry Pi.
For 'get' the manpage says
This requests a specific file to be sent to stdout. Just exit the script qith a non-zero exit statis to reject the transfer
Code: Select all
# PUT request works fine.
if sys.argv[1] == 'put':
#Get params and values
params = {}
while True:
data = sys.stdin.readline()
if data == '\n':
break
params[data.split(':', 1)[0]] = data.split(':', 1)[1].strip()
sys.stderr.write(str(params) + '\n')
#Send OK to start transfer of data
sys.stdout.write('OK\n')
sys.stdout.flush()
# Write the file to disk
f = open(params['Name'], 'w')
data = sys.stdin.read()
f.write(data)
f.close()
# GET Request is called
elif sys.argv[1] == 'get':
# Also get params first
params = {}
while True:
data = sys.stdin.readline()
if data == '\n':
break
params[data.split(':', 1)[0]] = data.split(':', 1)[1].strip()
# Send file to stdout.
# Tried with tempfile.SpooledTemporaryFile()
# writing result to tempfile and sys.stdout.write(tempfile.read())
result = 'Some data to send to Client'
sys.stdout.write(result)
sys.stdout.flush()
Code: Select all
0.1: OBEX_EV_REQ, OBEX_CMD_GET
0.1: Got header 0x01 with value length 14
0.1: name: "status"
0.1: Got header 0x42 with value length 16
0.1: type: "x-mobile/status"
0.1: Running script failed or no output data: Invalid argument
0.1: Sending response code 500
0.1: OBEX_EV_STREAMEMPTY, OBEX_CMD_CONNECT
0.1: Sending response code 500
0.1: OBEX_EV_LINKERR, OBEX_CMD_GET
Code: Select all
0.1: Running script failed or no output data: Success
Maybe I'm just doing some little error. Hopefully..
Thanks all for your help
d-aro