我那个是 Winsock,你也知道了。
现在就是别人用我的东西,说他那边有防火墙传东西传不过来,必须要被动模式才能传东西过来.他不愿把防火墙关掉(求人办事就是恶心!!!)哎,现在我想用winsock来重新写,可是网络的东西我接触的不多,所以想请大哥把你写的东西借我看看,跪求啊!!!!
我也免得让你恶心了,也不知道是谁大谁小。。。
我就把整个 Winsock 接受信息的事件发上吧
主要就是 select case 那里是判断得到的消息的号码(类型)
发送 "PASV"[换行符] 后从服务器返回的消息是
227 Entering Passive Mode (xxx,xxx,xxx,xxx,xxx)
去 227 的 case 看,就是得到数据端口的过程:
其他的号码看你的需要定,有一些是登录服务器用的,加了注释你可以看一下
ps: 你了不了解 ftp 的命令?网上有当。
Private Sub sckCommand_DataArrival(ByVal bytesTotal As Long)
Dim strData As String, iFTPCode As Integer
Dim strMsgs() As String, iMsg As Integer
Dim i As Integer, i2 As Integer, l As Long
Dim strTemp As String, strTemp2 As String
sckCommand.GetData strData, vbString
strLastMsg = strData
strMsgs = Split(strData, vbNewLine)
For iMsg = 0 To UBound(strMsgs) - 1
iFTPCode = 0 '<--必要语句!
If Left(strMsgs(iMsg), 4) Like "??? " Then
iFTPCode = Trim(Left(strMsgs(iMsg), 3))
End If
ShowMessage strMsgs(iMsg), mcRecvMsg
Select Case iFTPCode
Case 220 '登录
fsFTPState = fsConnected
SetStatusText "正在登录......"
SendCommand "USER " & SiteConn.strUsername
Case 331 '密码
SendCommand "PASS " & SiteConn.strPassword
Case 230 '登录成功
fsFTPState = fsLogined
SetStatusText "登录成功。"
If SiteConn.strRemotePath <> "/" Then
ChangeRWD SiteConn.strRemotePath
Else
PrintDir
End If
Case 530 '登录失败
fsFTPState = fsIdle
ShowMessage "登录失败!", msErrMsg
SetStatusText "登录失败。"
MsgBox "对不起,登录失败,请检查用户名或密码是否正确。", vbExclamation, "错误"
Disconnect
Case 257 '返回目录名称或创建目录成功
If fsFTPState = fsPrintDir Then
i = InStr(strMsgs(iMsg), """") + 1
i2 = InStr(i, strMsgs(iMsg), """")
strTemp = Mid(strMsgs(iMsg), i, i2 - i)
strRemotePath = strTemp
txtRemote.Text = strTemp
ElseIf fsFTPState = fsMakeDir Then
ShowMessage "创建目录成功!", msStatMsg
End If
ListDir 0 '刷新目录
Case 200 '改变传输类型或文件操作完成
If fsFTPState = fsChangeDir Then
PrintDir
Else
GoPASV
End If
Case 227 '成功进入 PASV 模式
' SEE HERE-------------------------------------------------------------------------
strMsgs(iMsg) = Replace(strMsgs(iMsg), ",", ".")
i = InStr(strMsgs(iMsg), sckCommand.RemoteHostIP) + Len(sckCommand.RemoteHostIP) + 1
i2 = InStr(i, strMsgs(iMsg), ".")
strTemp = Mid(strMsgs(iMsg), i, i2 - i)
i = i2 + 1
i2 = InStr(i, strMsgs(iMsg), ")")
strTemp2 = Mid(strMsgs(iMsg), i, i2 - i)
l = Val(strTemp) * 256 + Val(strTemp2)
ShowMessage "正在连接数据端口......", msStatMsg
SetStatusText "正在连接数据端口......"
sckData.Close
sckData.Connect SiteConn.strSiteIP, l
Case 150 '开始数据传输
If sckData.Tag = "Up" Then
UploadData
End If
Case 226 '传输完成
fsFTPState = fsIdle
ShowMessage "传输完成。", msStatMsg
SetStatusText "传输完成。"
Select Case sckData.Tag
Case "Up"
If iQueueFiles = -1 Then
ListDir 0
Else
GoQueueFile
End If
End Select
Case 250 '文件操作完成
Select Case fsFTPState
Case fsChangeDir
PrintDir
Case fsDelete
ShowMessage "删除文件完成。", msStatMsg
If iRDelItemsNum = 0 Or (iRDelCur = iRDelItemsNum) Then
Erase iRDelItems()
iRDelItemsNum = -1
iRDelCur = -1
ListDir 0
Else
iRDelCur = iRDelCur + 1
If FTPFiles(iRDelItems(iRDelCur)).bFolder Then
RemoveRDir iRDelItems(iRDelCur), False
Else
DeleteRFile iRDelItems(iRDelCur), False
End If
End If
Case fsRename
ShowMessage "重命名/移动文件完成。", msStatMsg
sckData.Tag = "List"
If Not SetType(0) Then GoPASV
End Select
Case 350 '重命名为新文件名
SendCommand "RNTO " & strRRenTo
Case 550 '未执行请求操作
Select Case fsFTPState
Case fsChangeDir
ShowMessage "无法跳转目录!", msErrMsg
Case fsUpload
ShowMessage "无法上传该文件: " & QueueFiles(iQueueTop).strFilename & "!", msErrMsg
picProgress.Visible = False
Close #1
Case fsDownload
ShowMessage "无法下载该文件: " & QueueFiles(iQueueTop).strFilename & "!", msErrMsg
picProgress.Visible = False
Close #1
Case fsMakeDir
ShowMessage "创建目录失败!可能是目录名已存在,也可能是您没有在此路径下创建目录的权限。", msErrMsg
Case fsRename
ShowMessage "重命名或移动文件/目录失败!", msErrMsg
End Select
If fsFTPState = fsChangeDir Then
txtRemote.Text = strRemotePath
ListDir 0
Else
ChangeRWD strRemotePath
End If
Case 553 '未执行请求命令
ShowMessage "请求的命令失败!", msErrMsg
ChangeRWD strRemotePath
Case 426 '中止传输
If fsFTPState = fsUpload Or fsFTPState = fsDownload Then
ShowMessage "中止传输,传输文件失败!", msErrMsg
lSent = 0
EndOfTransfer IIf(fsFTPState = fsUpload, 0, 1)
ListDir 0
End If
Case 221, 421, 500 '断开连接
Disconnect
End Select
Next
End Sub
再有不懂再问
[此贴子已经被作者于2006-8-4 12:35:14编辑过]