<!-- 一个接收文件的例子, 附带进度显示 --> <script language="vbscript"> <!-- sub btnreceivefile_onclick myform.noise.value = 0 myform.redundancy.value = 0 call nsfile1.ftsregisterstatuscallback(0, 0, 4096, 4096, 0, 0, 0, 0, 0, 0, 0) on error resume next call nsfile1.ftsstartfiletransferreceive("239.230.50.50", 5050, "", "%temp%/", 0, 1025) if err.number then msgbox "start error = " & returnerror(err.number) end sub
sub btncancelfile_onclick call nsfile1.ftscancelfiletransferreceive msgbox "transfer cancelled. error = " & returnerror(nsfile1.result) end sub
sub nsfile1_ftsontransferprogress myform.totalbytes.value = nsfile1.numtotalbytestransferred myform.databytes.value = nsfile1.numtotaldatabytestransferred myform.packets.value = nsfile1.numpacketstransferred myform.bogus.value = nsfile1.numboguspacketsreceived end sub
sub nsfile1_ftsontransfercompleted msgbox "transfer completed. error = " & returnerror(nsfile1.result) totalbytes = nsfile1.numtotalbytestransferred if totalbytes > 0 then databytes = nsfile1.numtotaldatabytestransferred myform.redundancy.value = int(((totalbytes - databytes)/totalbytes)*100) packets = nsfile1.numpacketstransferred bogus = nsfile1.numboguspacketsreceived myform.noise.value = int(bogus/packets) myform.totalbytes.value = nsfile1.numtotalbytestransferred myform.databytes.value = nsfile1.numtotaldatabytestransferred myform.packets.value = nsfile1.numpacketstransferred myform.bogus.value = nsfile1.numboguspacketsreceived end if end sub
sub btnabout_onclick call nsfile1.aboutbox() end sub
function returnerror(byval errnum) select case errnum case 0 errstring = "no error" case 1 errstring = "already requested" case -2147467260 errstring = "cancelled" case -2147467259 errstring = "failed" case -2147287038 errstring = "file not found" case -2147024882 errstring = "out of memory" case -2147024809 errstring = "invalid parameter" case -2147023436 errstring = "timed out" case else errstring = "unknown error " & cstr(hex(errnum)) end select returnerror = errstring end function
<script language="vbscript"> <!-- sub btnreceivefile_onclick on error resume next '--- initialize form values. myform.mytime.value = "" myform.starttime.value = "" myform.numfiles.value = "" myform.perfiledata.value = "" myform.totalbytes.value = "" myform.databytes.value = "" myform.currfile.value = "" myform.currattr.value = "" myform.currsize.value = "" myform.packets.value = "" myform.bogus.value = "" myform.packdrop.value = "" myform.packcorr.value = "" myform.packdup.value = "" myform.srcpath.value = "" myform.destpath.value = "" myform.endaddr.value = "" myform.endport.value = "" myform.srcaddr.value = "" myform.srcport.value = "" myform.locaddr.value = "" myform.locport.value = "" myform.lastport.value = "" '--- determine routing. if myform.ipaddr.value = "" then myform.routing.value = " listen for unicast" myipaddr = "" nsfile1.type = 2 else myipaddr = myform.ipaddr.value myform.routing.value = "listen for multicast" end if '--- set up callbacks. call nsfile1.ftsregisterstatuscallback(4096, 5, 8192, 8192, 1, 1, 1, 1, 1, 4+8+16+32, 0) '--- start transfer. call nsfile1.ftsstartfiletransferreceive(myipaddr, myform.ipport.value, myform.filter.value, myform.filepath.value, myform.attributes.value, myform.flags.value) if err.number then msgbox "start error = " & returnerror(err.number) end sub
sub btncancelfile_onclick on error resume next call nsfile1.ftscancelfiletransferreceive msgbox "transfer cancelled. error = " & returnerror(nsfile1.result) end sub
sub nsfile1_ftsontransferstarted on error resume next myform.starttime.value = time() myform.srcpath.value = nsfile1.sourcefilepath myform.destpath.value = nsfile1.destinationfilepath myform.endaddr.value = nsfile1.endpointaddress myform.endport.value = nsfile1.endpointport myform.srcaddr.value = nsfile1.sourceaddress myform.srcport.value = nsfile1.sourceport myform.locaddr.value = nsfile1.localaddress myform.locport.value = nsfile1.localport myform.lastport.value = nsfile1.localportused end sub
sub nsfile1_ftsonfiletransferstarted on error resume next myform.currfile.value = nsfile1.currentfilepath myform.currattr.value = nsfile1.currentfileattributes myform.currsize.value = nsfile1.currentfilesize end sub
sub nsfile1_ftsonfiletransfercompleted on error resume next myform.numfiles.value = nsfile1.numfilestransferred end sub
sub nsfile1_ftsontransferprogress on error resume next myform.numfiles.value = nsfile1.numfilestransferred progbar = int((nsfile1.percentfiledatabytestransferred)/5) if progbar < 20 then myform.perfiledata.value = string(progbar, "?) else myform.perfiledata.value = "file transferred!" end if myform.totalbytes.value = nsfile1.numtotalbytestransferred myform.databytes.value = nsfile1.numtotaldatabytestransferred myform.packets.value = nsfile1.numpacketstransferred myform.bogus.value = nsfile1.numboguspacketsreceived myform.packdrop.value = nsfile1.numpacketsdropped myform.packcorr.value = nsfile1.numpacketscorrected myform.packdup.value = nsfile1.numduplicatepacketsreceived end sub
sub btnabout_onclick call nsfile1.aboutbox() end sub
function returnerror(byval errnum) select case errnum case 0 errstring = "no error" case 1 errstring = "already requested" case -2147467260 errstring = "cancelled" case -2147467259 errstring = "failed" case -2147287038 errstring = "file not found" case -2147024882 errstring = "out of memory" case -2147024809 errstring = "invalid parameter" case -2147023436 errstring = "timed out" case else errstring = "unknown error " & cstr(hex(errnum)) end select returnerror = errstring end function --> </script>