The script getfile1.py used by pad to receive files from PC
In this article, the android mobile phone receives files from the PC using the script getfile2.py, which is easier to use than getfile1.py.
#-*-Coding: utf8-*-import androidimport sys, OS, timefrom socket import * droid = android. android () def now (): return time. strftime ('% Y-% m-% d % x', time. localtime () if droid. checkWifiState (). result = False: print 'check Wifi state' sys. exit (4) base_dir = '/mnt/sdcard/sl4a/scripts/' if not OS. path. isdir (base_dir): print base_dir, 'is not dir' sys. exit (4) def show_dir (path = base_dir): "" Shows the conte ETS of a directory in a list view. "# The files & directories under" path ". nodes = sorted (OS. listdir (path) # Make a way to go up a level. if path! = Base_dir: nodes. insert (0 ,'.. ') droid. dialogCreateAlert (OS. path. basename (path ). title () droid. dialogSetItems (nodes) droid. dialogShow () # Get the selected file or directory. result = droid. dialogGetResponse (). result droid. dialogDismiss () if 'item' not in result: return target = nodes [result ['item'] target_path = OS. path. join (path, target) if target = '.. ': target_path = OS. path. dirname (path) if OS. path. isdir (target_path): show_dir (target_path) elif OS. path. splitext (target) [1]. lower () = '. py': return target_path # inform the user. else: droid. makeToast ('only. py files are currently supported! ') Show_dir (path) path = show_dir () filename = droid. dialogGetInput (u "receiving files from PC", OS. path. dirname (path), OS. path. basename (path )). resultif filename is not None: path = OS. path. dirname (path) + '/' + filenameprint pathbufsz = 1024 host = '2017. 168.0.103 'port = 55555 sock = socket (AF_INET, SOCK_STREAM) sock. connect (host, port) sock. send (filename + '\ n') # send remote name with dirfile = open (path, 'wb') # create local file in cwdwhile True: data = sock. recv (bufsz) # get up to 1 K at a time if not data: break # till closed on server side file. write (data) # store data in local filefile. close () sock. close () print 'client get', filename, 'at', now ()