| 发表于:2007-09-13 13:56:103楼 得分:0 |
这是服务器端主要的接收代码! private sub up_dataarrival(index as integer, byval bytestotal as long) dim data as string, filesize as long, percent as long 'on error goto errorhandle call up(index).getdata(data, , bytestotal) if left(data, 5) = "file= " then 'received file upload confirmation from 'client... separate data, and set variables ' temp$ = right(data, len(data) - 5) ' slash = findreverse(temp$, "\ ") ' parentfolder$ = left(temp$, slash) ' 'debug.print data ' if exists(parentfolder$) = false then ' mkdir (parentfolder$) ' end if dim folders2create as new collection dim objfso as new filesystemobject data = right(data, len(data) - 5) colon = instr(data, ": ") nextstring = right(data, len(data) - colon) realcolon = instr(nextstring, ": ") + 2 filesize1 = right(data, len(data) - realcolon) debug.print filesize1 filename = left(data, realcolon - 1) filetransferadd filename, filesize1, up(index).remotehostip, " " 'add item to list for file transfers pf = objfso.getparentfoldername(filename) do while pf <> " ": doevents if objfso.folderexists(pf) = false then folders2create.add pf end if pf = objfso.getparentfoldername(pf) loop 'create folders (if needed) on error resume next for x = folders2create.count to 1 step -1 mkdir folders2create.item(x) next x set folders2create = nothing 'delete the file if exists(filename) then kill filename 'open the file so that packets received can be directly 'written to the already open disk file filenum = freefile() i = freefile open filename for binary access write as #filenum if filesize1 = 0 then 'if the file size is 0 bytes, just close the file 'and tell the client it 's done receiving the file close #filenum call frmmain.up(index).senddata( "filedone ") soutput "received ' " & filename & " ' ( " & filesize1 & " bytes) from ip ' " & up(index).remotehostip & " ' " exit sub end if 'inform the client that it can start sending 'data packets (the default is 2048 bytes) call frmmain.up(index).senddata( "begin ") exit sub end if 'inform the client that the packet was received sucessfully put #filenum, , data doevents debug.print lof(filenum) frmmain.up(index).senddata ( "ok ") 'write the incoming data directly to the disk file 'if the size of the disk file matches the size as told 'by the client, we are done receiving this file, so 'close it and inform the client that the file was 'received successfully if lof(filenum) = filesize1 then close #filenum debug.print "closed file#: " & filenum & " up " call frmmain.up(index).senddata( "filedone ") soutput "received ' " & filename & " ' ( " & filesize1 & " bytes) from ip ' " & up(index).remotehostip & " ' " 'if logging is enabled in options, write this transfer to the log if getsetting( "andromeda ", "settings ", "writetransferlog ") = "1 " then writelog app.path + "\ftransfer.txt ", "received ' " & filename & " ' ( " & filesize1 & " bytes) from ip ' " & up(index).remotehostip & " ' time/date= " & format(now, "hh:mm:ss am/pm - mm/dd/yyyy ") end if filenum = 0 'set filenum back to zero exit sub end if exit sub errorhandle: soutput ( "error in up( " & index & "): " & err.description & " #: " & err.number) end sub | | |
|