'代码放在模块中,sendfile
Option Explicit
Public Sub sendfile(filename As String)
Dim FreeF As Integer
Dim lenfile As Long
Dim nr() As Byte
Dim ipos As Long
Dim imax As Long
FreeF = FreeFile
Open filename For Binary As #FreeF
DoEvents
lenfile = LOF(FreeF)
imax = 1024
If lenfile <= imax Then
ReDim nr(1 To lenfile)
Get #FreeF, , nr
Close #FreeF
Form1.Winsock1.SendData nr
End If
Do Until (ipos >= (lenfile - imax))
ReDim nr(1 To imax)
Get #FreeF, ipos + 1, nr
Form1.Winsock1.SendData nr
ipos = ipos + imax
Loop
ReDim nr(1 To lenfile - ipos)
Get #FreeF, ipos + 1, nr
Form1.Winsock1.SendData nr
Close #FreeF
End Sub
其中.filename是文件地址,这个方法是通过winsock发送
原理是打开一个文件,用二进制,和文件资源管理器远离差不多
然后分块发送文件,在客户端生成exe写入二进制
如果是单纯的ftp的话,可以直接使用inet控件,这个比较简单,可以自己看一些VB inet连接FTP等