server '============================================== 'Written by Igor Ostrovsky ([email protected]) 'Visual Basic 911 (http://www.ostrosoft.com/vb) '============================================== Option ExplicitDim lPos As LongPrivate Sub cmdRun_Click() If cmdRun.Caption = "Run" Then cmdRun.Caption = "Stop" wsTCP(0).LocalPort = 1111 wsTCP(0).Listen Else wsTCP(0).Close cmdRun.Caption = "Run" End If End SubPrivate Sub Drive1_Change() Dir1.Path = Drive1.Drive & "\" End SubPrivate Sub wsTCP_Close(Index As Integer) Close #1 Unload wsTCP(1) End SubPrivate Sub wsTCP_ConnectionRequest(Index As Integer, ByVal requestID As Long) Load wsTCP(1) wsTCP(1).Accept requestID If Dir(Dir1.Path & "\temp") <> "" Then Kill Dir1.Path & "\temp" Open Dir1.Path & "\temp" For Binary As 1 lPos = 1 End SubPrivate Sub wsTCP_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim buffer() As Byte wsTCP(1).GetData buffer Put #1, lPos, buffer lPos = lPos + UBound(buffer) + 1 End Sub
client '============================================== 'Written by Igor Ostrovsky ([email protected]) 'Visual Basic 911 (http://www.ostrosoft.com/vb) '============================================== Option ExplicitDim buffer() As Byte Dim lBytes As LongPrivate Sub cmdBrowse_Click() dlg.ShowOpen txtFile = dlg.FileName End SubPrivate Sub cmdSend_Click() cmdSend.Enabled = False lBytes = 0 ReDim buffer(FileLen(dlg.FileName) - 1) Open dlg.FileName For Binary As 1 Get #1, 1, buffer Close #1 Load wsTCP(1) wsTCP(1).RemoteHost = "172.16.1.17" wsTCP(1).RemotePort = 8896 wsTCP(1).Connect lblStatus = "Connecting..." End SubPrivate Sub wsTCP_Close(Index As Integer) lblStatus = "Connection closed" Unload wsTCP(1) End SubPrivate Sub wsTCP_Connect(Index As Integer) lblStatus = "Connected" wsTCP(1).SendData buffer End SubPrivate Sub wsTCP_SendComplete(Index As Integer) lblStatus = "Send complete" Unload wsTCP(1) cmdSend.Enabled = True End SubPrivate Sub wsTCP_SendProgress(Index As Integer, ByVal bytesSent As Long, ByVal bytesRemaining As Long) lBytes = lBytes + bytesSent lblStatus = lBytes & " out of " & UBound(buffer) & " bytes sent" End Sub
这是最简单的。
shell("copy filename \\共享路径")
'==============================================
'Written by Igor Ostrovsky ([email protected])
'Visual Basic 911 (http://www.ostrosoft.com/vb)
'==============================================
Option ExplicitDim lPos As LongPrivate Sub cmdRun_Click()
If cmdRun.Caption = "Run" Then
cmdRun.Caption = "Stop"
wsTCP(0).LocalPort = 1111
wsTCP(0).Listen
Else
wsTCP(0).Close
cmdRun.Caption = "Run"
End If
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive & "\"
End SubPrivate Sub wsTCP_Close(Index As Integer)
Close #1
Unload wsTCP(1)
End SubPrivate Sub wsTCP_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Load wsTCP(1)
wsTCP(1).Accept requestID
If Dir(Dir1.Path & "\temp") <> "" Then Kill Dir1.Path & "\temp"
Open Dir1.Path & "\temp" For Binary As 1
lPos = 1
End SubPrivate Sub wsTCP_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim buffer() As Byte
wsTCP(1).GetData buffer
Put #1, lPos, buffer
lPos = lPos + UBound(buffer) + 1
End Sub
'==============================================
'Written by Igor Ostrovsky ([email protected])
'Visual Basic 911 (http://www.ostrosoft.com/vb)
'==============================================
Option ExplicitDim buffer() As Byte
Dim lBytes As LongPrivate Sub cmdBrowse_Click()
dlg.ShowOpen
txtFile = dlg.FileName
End SubPrivate Sub cmdSend_Click()
cmdSend.Enabled = False
lBytes = 0
ReDim buffer(FileLen(dlg.FileName) - 1)
Open dlg.FileName For Binary As 1
Get #1, 1, buffer
Close #1
Load wsTCP(1)
wsTCP(1).RemoteHost = "172.16.1.17"
wsTCP(1).RemotePort = 8896
wsTCP(1).Connect
lblStatus = "Connecting..."
End SubPrivate Sub wsTCP_Close(Index As Integer)
lblStatus = "Connection closed"
Unload wsTCP(1)
End SubPrivate Sub wsTCP_Connect(Index As Integer)
lblStatus = "Connected"
wsTCP(1).SendData buffer
End SubPrivate Sub wsTCP_SendComplete(Index As Integer)
lblStatus = "Send complete"
Unload wsTCP(1)
cmdSend.Enabled = True
End SubPrivate Sub wsTCP_SendProgress(Index As Integer, ByVal bytesSent As Long, ByVal bytesRemaining As Long)
lBytes = lBytes + bytesSent
lblStatus = lBytes & " out of " & UBound(buffer) & " bytes sent"
End Sub