Codebase list pysmb / 91ea320
Merge PR #160 into dev-1.2.x Michael Teo 3 years ago
1 changed file(s) with 33 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1515 Example
1616 -------
1717
18 The following code snippet illustrates file retrieval.::
18 The following code snippet illustrates file retrieval with Python 2.::
1919
2020 # -*- coding: utf-8 -*-
2121 import urllib2
3333 # Process fh2 like a file-like object and then close it.
3434 fh2.close()
3535
36 The following code snippet illustrates file upload. You need to provide a file-like object for the *data* parameter in the *open()* method::
36 The following code snippet illustrates file upload with Python 2. You need to provide a file-like object for the *data* parameter in the *open()* method::
3737
3838 import urllib2
3939 from smb.SMBHandler import SMBHandler
4545
4646 # Reading from fh will only return an empty string
4747 fh.close()
48
49
50 The following code snippet illustrates file retrieval with Python 3.::
51
52 import urllib
53 from smb.SMBHandler import SMBHandler
54
55 director = urllib.request.build_opener(SMBHandler)
56 fh = director.open('smb://myuserID:[email protected]/sharedfolder/rfc1001.txt')
57
58 # Process fh like a file-like object and then close it.
59 fh.close()
60
61 # For paths/files with unicode characters, simply pass in the URL as an unicode string
62 fh2 = director.open(u'smb://myuserID:[email protected]/sharedfolder/测试文件夹/垃圾文件.dat')
63
64 # Process fh2 like a file-like object and then close it.
65 fh2.close()
66
67 The following code snippet illustrates file upload with Python 3. You need to provide a file-like object for the *data* parameter in the *open()* method::
68
69 import urllib
70 from smb.SMBHandler import SMBHandler
71
72 file_fh = open('local_file.dat', 'rb')
73
74 director = urllib.request.build_opener(SMBHandler)
75 fh = director.open('smb://myuserID:[email protected]/sharedfolder/upload_file.dat', data = file_fh)
76
77 # Reading from fh will only return an empty string
78 fh.close()