2007-08-10, 16:43
Any scripters using the pysamba lybrary have experience transfering large files.
I can transfer text files and jpg's that are under 1MB. When I try and transfer large 12MB+ files it timeout.
I can use the httpapi, but it just bothered me that pysamba failed.
I can transfer text files and jpg's that are under 1MB. When I try and transfer large 12MB+ files it timeout.
Code:
import sys
import os
import xbmc
import xbmcgui
import smb
import nmb
import re
import traceback
def get_browse_dialog( default="", heading="", dlg_type=1, shares="files", mask="", use_thumbs=False, treat_as_folder=False ):
""" shows a browse dialog and returns a value
- 0 : ShowAndGetDirectory
- 1 : ShowAndGetFile
- 2 : ShowAndGetImage
- 3 : ShowAndGetWriteableDirectory
"""
dialog = xbmcgui.Dialog()
value = dialog.browse( dlg_type, heading, shares, mask, use_thumbs, treat_as_folder, default )
return value
filename = get_browse_dialog( heading = "File to copy" )
share_string = get_browse_dialog( heading = "Samba folder to save to", dlg_type=0 )
share_string_list = share_string.split( "/" )
remote_name = share_string_list[ 2 ]
remote_ip = nmb.NetBIOS().gethostbyname( remote_name )[ 0 ].get_ip()
remote_share = share_string_list[ 3 ]
remote_username = "Guest"
remote_password = ""
remote_object = smb.SMB( remote_name, remote_ip )
if ( remote_object.is_login_required() ):
remote_object.login( remote_username, remote_password )
# copy the file using pysamba
file_object = open( filename, "rb")
remote_object.stor_file( remote_share, "/".join( share_string_list[ 4 : ] ) + os.path.basename( filename ), file_object.read, password=remote_password, timeout=20 )
file_object.close()
# using httpapi works with large files
#xbmc.executehttpapi("FileCopy(%s,%s)" % ( filename, share_string + os.path.basename( filename ), ) )
I can use the httpapi, but it just bothered me that pysamba failed.