forked from balle/python-network-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobex_push.py
36 lines (25 loc) · 807 Bytes
/
obex_push.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python3
import sys
from os.path import basename
from PyOBEX import client, headers, responses
if len(sys.argv) < 4:
print(sys.argv[0] + ": <btaddr> <channel> <file>")
sys.exit(0)
btaddr = sys.argv[1]
channel = int(sys.argv[2])
my_file = sys.argv[3]
c = client.Client(btaddr, channel)
r = None
try:
print("Connecting to %s on channel %d" % (btaddr, channel))
r = c.connect(header_list=(headers.Target("OBEXObjectPush"),))
except OSError as e:
print("Connect failed. " + str(e))
if isinstance(r, responses.ConnectSuccess):
print("Uploading file " + my_file)
r = c.put(basename(my_file), open(my_file, "rb").read())
if not isinstance(r, responses.Success):
print("Failed!")
c.disconnect()
else:
print("Connect failed!")