设置一个byte(),把*.exe转成二进制赋值给byte()再send 给客户端的容器里, 在客户端写出并winexec or shell吧!*.txt就简单多了!首先open它,值给变量或容器,然后send即可再在客户端dataarrival中……
哎……又一个坏孩子!
哎……又一个坏孩子!
解决方案 »
- 知道位图文件结构,如果把一张图片的信息读入这个结构?
- 如果服务端的数据表结构允许用户修改的话,如何用SOAP处理呢?
- 如何用vb语句或SQL语句启动和终止数据库服务器
- 高手进来看看.关于程序移动的问题.小弟困恼很久了!.问题解决马上结帖
- 菜鸟问题!VB中怎样画线?
- (急急急)同一个teechart控件如何Import多个已Export的文件,并同时显示进行比对
- 李大斑竹:关注一下我的问题,关于查询结果输出到excel表的问题!
- VBS中Label写入txt
- 一个大家提过好多次但还没有好的解决办法的问题(TreeView背景色、前景色)
- 请问在VB中怎么用TOOLBAR???
- 又一难题,如何使n*m个image组合显示一个图像?
- 如何读出任意Access数据库的表名和字段名?
在里头你可以找到如何发送文件了里面为了确保发送不至于丢失,采用了应答式发送,
另外一次发送的字节数也能控制.
Option Explicit
Dim mybyte() As Byte '发送方数组
Const filecomesMSG = "a file is coming " '有文件到来
Const RemoteIsReadyMSG = "I'm ready " '准备好了
Const FileisOverMSG = "the file is ended" '文件完毕
Const RemoteDenyMSG = "the user canceled"
Const filecountMSG = "the file lengh is"
Dim arrdata() As Byte '收到的信息
Dim filesave As Integer '保存文件的句柄
Dim filehandle As Integer '发送方文件的句柄
Dim MyLocation As Double
Dim myMSG As String '消息
Dim FileisTransfer As Boolean '文件正在传送
Dim Isendfile As Boolean '是否是本人在传送
Dim FileisOver As Boolean '文件是否已经完毕
Dim Counttime As Integer '需要传递的次数
Dim totaltime As Variant
Private Sub cmdsend_Click()
On Error GoTo errorhandle
'this is needed for correct filename
filehandle = FreeFile
If Mid(File1.Path, Len(File1.Path), 1) = "\" Then
Open File1.Path & File1.FileName For Binary Access Read As #filehandle
Else
Open File1.Path & "\" & File1.FileName For Binary Access Read As #filehandle
End If
Isendfile = True '是本人在传送
FileisOver = False '文件刚开始
cmdsend.Enabled = False
Label1.Caption = "Wait for reply..."
MsgBox ("the selected file size is " & LOF(filehandle) & " bytes")
totaltime = Int(LOF(filehandle) / 4000 + 1)
MyLocation = Loc(filehandle)
Winsock.SendData filecomesMSG & File1.FileName '发送发出文件信息
Winsock.SendData filecountMSG & totaltime
Exit Sub
errorhandle: MsgBox ("You havn't choose a file!")
End SubPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End SubPrivate Sub Form_Load()
Drive1.Drive = "c:\"
Winsock.RemoteHost = "255.255.255.255"
Winsock.LocalPort = 7904
Winsock.Bind 7904
Winsockfile.RemoteHost = "255.255.255.255"
Winsockfile.LocalPort = 7905
Winsockfile.Bind 7905
FileisTransfer = False 'initialize the bool value
Isendfile = False
FileisOver = True
Counttime = 0
Label1.Caption = "Ready..."
End SubPrivate Sub Timer1_Timer()
Dim i As Integer
If LOF(filehandle) - MyLocation > 4000 Then
ReDim mybyte(0 To 4000)
Get #filehandle, , mybyte
MyLocation = Loc(filehandle)
Winsockfile.SendData mybyte
Counttime = Counttime + 1
Label1.Caption = "the select file is being transfered..." & "about " & Counttime & " / " & totaltime
Timer1.Enabled = False
Else
ReDim mybyte(0 To LOF(filehandle) - MyLocation - 1)
Get #filehandle, , mybyte
Winsockfile.SendData mybyte
FileisTransfer = False
Timer1.Enabled = False
FileisOver = True
End IfEnd SubPrivate Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Winsock.GetData myMSG
Select Case Mid(myMSG, 1, 17)
Case filecomesMSG '这些消息发送方和接受方都可收到
'do display a form
If Not Isendfile Then '接受方处理这些事情
On Error GoTo errorhandle
CommonDialog1.FileName = Mid(myMSG, 17, Len(myMSG))
CommonDialog1.ShowSave
filesave = FreeFile
FileisTransfer = True
cmdsend.Enabled = False
Open CommonDialog1.FileName For Binary Access Write As #filesave
Winsock.SendData RemoteIsReadyMSG
Label1.Caption = "the select file is being transfered..."
End If
Case RemoteIsReadyMSG
'do begin transfer a file
'如果文件还没有结束,也就是说,只有主机才能受到
If Isendfile Then
If Not FileisOver Then
Timer1.Enabled = True
Label1.Caption = "the select file is being transfered..."
Else
Winsock.SendData FileisOverMSG
End If
End If
Case FileisOverMSG
If Not Isendfile Then '客户机处理
Close #filesave
FileisTransfer = False
Else '主机处理
Isendfile = False
Close #filehandle
End If
MsgBox ("the file is transfered successfully!") '大家一起处理
Isendfile = False
cmdsend.Enabled = True
Label1.Caption = "Ready..."
Case RemoteDenyMSG
If Isendfile Then
MsgBox ("The user canceled this transfer session!")
Isendfile = False
FileisOver = True
cmdsend.Enabled = True
Label1.Caption = "Ready..."
Close #filehandle
End If
Case filecountMSG
If Not Isendfile Then
totaltime = Mid(myMSG, 17, Len(myMSG))
End If
End Select
Exit Sub
errorhandle: Winsock.SendData RemoteDenyMSG
End Sub
Private Sub writetofile()
Put #filesave, , arrdata
End SubPrivate Sub Winsockfile_DataArrival(ByVal bytesTotal As Long)
If FileisTransfer Then
Winsockfile.GetData arrdata, vbArray + vbByte, 4001
writetofile
Winsock.SendData RemoteIsReadyMSG
Counttime = Counttime + 1
Label1.Caption = "the select file is being transfered..." & "about " & Counttime & "/" & totaltime
End If
End Sub
我的写文件过程如下:
Dim fang() As Byte
wskWksbbsj.GetData fang, vbByte
Open ("c:\1\wkstn2.exe") For Binary Access Read Write As #1
Put #1, , fang
Close #1
读文件过程如下:
Dim fang() As Byte
Open ("e:\wkstn2.exe") For Binary Access Read Write As #1
ReDim fang(LOF(1)) As Byte
Get #1, 1, fang
Close #1
wskCtrlbbsj.SendData fang其中传递小于8K的可执行文件——OK
大于8K的可执行文件——NO
是否可以把文件分割成一个个的小数据包来发送,怎样做。请各位前辈详细指教