Accesssing network files via SMB in python
#1
hello

i have a central shared folder on my network which contains all the current tv listings in xmltv format. (thanks to the great xmltv software which grabs it off the net)

is there a way to read this file over the network within python, e.g:

xmldata = self.readfile("smb://user:password@computer/tv/listings.xml")

??

it doesn't seem to work, i get 'file not found'. (but i remember the author of the mythtv scripts saying that he had a workaround?) or could it be added into the current python implementation?

any help appreciated!


carlos




ps: currently, i get it to auto-ftp the listings to the xbox, but this is a hassle.
Reply
#2
i don't think there's a raw access to files over smb at the moment, you're probably best off using an ftp server on your pc and using python to download the file to your xbox, rather than uploading it to your xbox (if that's what you're doing)

python ftplib
Reply
#3
yeah, thanks for this, i guess so, if the ftp library is implemented in xmbc. but surely there must be a way to access remote files within python?

any developers care to comment, or have news on an implementation?
Reply
#4
python has socket support so it should be fairly easy to write a script that accesses an xbms server (the protocol is fairly simple). smb on the other hand, i believe is complex although i have never bothered to look at what is known about it.

while on this topic, this is another reason i believe xbms (or another simple protocol) is more important to xbmc than smb support (that and the fact i don't want to run samba just for the xbox).
Reply
#5
if you grab the xbmc mythtv source from http://changeling.ixionstudios.com/xbmc/,
you'll find smb.py and nmb.py in the python/lib directory. that is the library i am using to copy files from a smb share to the xbox. you can poke around the code to see how to use it. in particular, i just added smb.copytolocal() to copy a file from a remote share to the xbox file system. it should work fine for ascii files but at the moment seems to be broken for binary files.
Reply
#6
i would definitely love to test your xmltv script carlos if you get it working, i had trouble displaying the results
Reply
#7
thanks for that guys - i'll have a look at your smb.py; that would be brilliant if it works.

i'll post the xmltv script up here when it's done - it's nothing special, i haven't used proper xml parsing yet as i couldnt get enough sample code of expat, so it's all r.e. matching. but it works!
Reply
#8
btw, you'll want to grab version 0.5. version 0.4 did not have the copytolocal() method.

edit: i have updated xbmc mythtv to version 0.6 that fixes binary file copies. you can call smb.copytolocal( remoteservice, remotepath, localpath ) to copy files from a smb share to the xbox filesystem.
Reply
#9
madtw that's fantastic! thank you!

not sure on the syntax to use this. do you have an example function call for copytolocal ?

e.g. what if i want to copy
smb://domain;user:password@server/share/file.xml

do i do:
Quote:copytolocal("server/share","file.xml","q:\\folder\\dest.xml")

...and then edit the rest of the function call to be
Quote:def copytolocal(self, src_service, src_path, dest_path, callback = none, write_mode = smb_o_creat | smb_o_trunc, src_password = "password", dest_password = none, timeout = none):

....although i can't see where to put the username/domain, so is it:

Quote:copytolocal("domain;username:pass@server/share","file.xml","q:\\folder\\dest.xml")
Reply
#10
your best bet is to look in mytvshow.py to see how to call copytolocal(). the short answer is that you must instantiate a smb object first and do the login, then you can issue a copytolocal() method call. this is what it would look like with no error handling:

Quote: remote = smb.smb(host,hostip)
if remote.is_login_required():
remote.login( user, password, domain )

remotepath = "%s%s%s" % (dirpath,os.sep,filename)
remote.copytolocal( service, remotepath, localpath )

so host would be the "server" from your example. the service would be set to the "share". the rest of the fields should make sense.

btw, i found these nmb and smb modules on the web. since the copy() method assumed two remote smb shares, i added the copytolocal() method based on the code in the copy() method. i probably should've gotten rid of the rest of the parameters... but i wasn't sure what i was going to need until i got it working. once i got it working, i didn't go back to clean it up...
Reply

Logout Mark Read Team Forum Stats Members Help
Accesssing network files via SMB in python0