[在线等] vb关于ftp上传下载的 !!!!!!!!

zcm123 2004-12-17 02:53:35
上传的如何用winsock来实现上传到FTP服务器上指定的文件夹中阿(不存在文件夹时创建一个)

上传时当存在相同文件时提示.

如何下载文件阿?

如何获得FTP服务器上文件列表阿?当转换FTP服务器路径时,文件列表也跟着转换?

如何获得上传和下载每秒钟的传输速度阿???

谢谢各位了!


-----------------------------------------------------------------------------------------
还有关于上传断点续传,下载断点续传的
...全文
652 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcm123 2004-12-22
  • 打赏
  • 举报
回复
ok了 对谢各位提供的资料,我在其中的一个资料中找到了完整的模块 呵呵(有些投机取巧了)不过我在今后还是要提高自己,要不太郁闷了T_T 谢谢各位了 结贴!
likewindch 2004-12-21
  • 打赏
  • 举报
回复
下载进度 用本地文件大小/原文件大小 获得
我就是这么做的
但是不支持大于4G的文件
xiaohuangtao 2004-12-21
  • 打赏
  • 举报
回复
HTTP://www.smartmaildemo.com有个例子,第一个
zcm123 2004-12-20
  • 打赏
  • 举报
回复
这个 呵呵 请问下载的进度 和上传的进度如何获得阿?
AprilSong 2004-12-20
  • 打赏
  • 举报
回复
你直接到这里
http://www.5ivb.net/code/code_search.asp
找『FTP』就有不少现成的~

不够的话再看这里~
http://www.21code.com/codebase/?pos=list&type=search&key=FTP
adisen 2004-12-20
  • 打赏
  • 举报
回复
高!~实在是高~~
creazyfish 2004-12-20
  • 打赏
  • 举报
回复
这个是写的自定义控件,直接拷贝生成控件就可以了,至于显示文件进度的功能,也只能自己去添了,肯定不能很精确的。
creazyfish 2004-12-20
  • 打赏
  • 举报
回复
Private Sub UserControl_Resize()
UserControl.Width = Label1.Width
UserControl.Height = Label1.Height
End Sub

Private Sub UserControl_Terminate()
On Error Resume Next
Inet1.Execute , "CLOSE"
Inet1.Cancel
Call StopLogging
End Sub

Public Sub CloseSession()
On Error Resume Next
Inet1.Execute , "CLOSE"
Inet1.Cancel
End Sub

Public Sub DownLoadFile(SourceFile As String, DestFile As String)
On Error GoTo LocalError

LastAction = bwDownloading
If LoggingState = True Then
Print #1, Now & " Downloading file: " & SourceFile & " to " & DestFile
End If

Inet1.Execute "GET " & SourceFile & " " & DestFile
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on download: " & Inet1.ResponseInfo
End If

Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
End Sub

Public Sub UploadFile(LocalFile As String, RemoteFile As String)
On Error GoTo LocalError
LastAction = bwUploading
If LoggingState = True Then
Print #1, Now & " Uploading file from: " & LocalFile & " to " & RemoteFile
End If

Inet1.Execute , "PUT " & LocalFile & " " & RemoteFile
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on upload: " & Inet1.ResponseInfo
End If
Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
End Sub


Public Sub MkDir(DirSpec As String)
On Error GoTo LocalError
If LoggingState = True Then
Print #1, Now & " Creating directory: " & DirSpec
End If
Inet1.Execute , "MKDIR " & DirSpec
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on creating dir: " & Inet1.ResponseInfo
End If

Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
End Sub

Public Sub ChDir(DirSpec As String)
On Error GoTo LocalError
LastAction = bwGetResult
If LoggingState = True Then
Print #1, Now & " Change directory to: " & DirSpec
End If
Inet1.Execute , "CD " & DirSpec
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on changedir: " & Inet1.ResponseInfo
End If

Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If

End Sub

Public Sub DeleteFile(FileSpec As String)
On Error GoTo LocalError
If LoggingState = True Then
Print #1, Now & " Deleting file: " & FileSpec
End If
Inet1.Execute , "DELETE " & FileSpec
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Respsone on delete file: " & Inet1.ResponseInfo
End If

Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
End Sub

Public Sub DeletDir(FileSpec As String)
On Error GoTo LocalError
If LoggingState = True Then
Print #1, Now & " Delete directory: " & FileSpec
End If
Inet1.Execute , "RMDIR " & FileSpec
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on delete directory: " & Inet1.ResponseInfo
End If

Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If

End Sub

Public Function GetCurDir() As String
On Error GoTo LocalError
LastAction = bwGetCurDir

If LoggingState = True Then
Print #1, Now & " Getting current remote dir.."
End If
Inet1.Execute , "PWD"
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on getcurdir: " & Inet1.ResponseInfo
End If

GetCurDir = Trim(CurDir)
Exit Function
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
End Function

Public Sub Rename(SourceFile As String, DestFile As String)
On Error GoTo LocalError
If LoggingState = True Then
Print #1, Now & " Rename file: " & SourceFile & " to " & DestFile
End If
Inet1.Execute , "RENAME " & SourceFile & " " & DestFile
Do While Inet1.StillExecuting = True
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on rename file: " & Inet1.ResponseInfo
End If
Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
End Sub

Private Function IsNetConnected() As Boolean
IsNetConnected = InternetGetConnectedState(0, 0)
End Function

Public Property Get ResponseInfo() As String
ResponseInfo = Inet1.ResponseInfo
End Property

Public Property Get ResponseCode() As Long
ResponseCode = Inet1.ResponseCode
End Property

Public Sub StartLogging()
On Error GoTo LocalError
If LoggingState = False Then
Open LogFile For Output As #1
Print #1, Now & " Logging started"
LoggingState = True
End If
Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
End Sub

Public Sub StopLogging()
If LoggingState = True Then
Print #1, Now & " End logging"
Close #1
LoggingState = False
End If
End Sub

Public Sub AddLogEntry(strLogEntry As String)
If LoggingState = True Then
Print #1, Now & " " & strLogEntry
End If
End Sub

Public Function StillExecuting() As Boolean
StillExecuting = Inet1.StillExecuting
End Function

Public Sub SetTo(s As String)
LastAction = bwGetResult
Inet1.Execute , "TYPE " & UCase(s)
Do While Inet1.StillExecuting = True
DoEvents
Loop

End Sub
creazyfish 2004-12-20
  • 打赏
  • 举报
回复
'引用inet
Option Explicit

Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long

Enum EnumBusyWith
bwNothing = 0
bwListing = 1
bwDownloading = 2
bwUploading = 3
bwGetCurDir = 4
bwGetResult = 5
End Enum

Public FtpUrl As String
Public Username As String
Public PassWord As String
Public TimeOut As Long
Public ProxyServer As String
Public ProxyPort As Long
Public InitDir As String
Public Files As New Collection
Public LogFile As String
Dim LoggingState As Boolean
Dim LastAction As EnumBusyWith
Dim CurDir As String
Dim sResponseString As String
Dim lResponseCode As Long

Event Error(ErrorCode As Long)

Public Sub Connect(Optional ByVal FtpUrl As String, Optional ByVal Username As String, Optional ByVal PassWord As String)
On Error Resume Next
Inet1.Cancel

On Error GoTo LocalError

If ProxyServer = "" Then
Inet1.AccessType = icUseDefault
Else
Inet1.AccessType = icNamedProxy
Inet1.Proxy = ProxyServer & ":" & Trim(CStr(ProxyPort))
End If

Inet1.URL = FtpUrl
Inet1.Username = Username
Inet1.PassWord = PassWord
If TimeOut = 0 Then
Inet1.RequestTimeout = 40
Else
Inet1.RequestTimeout = TimeOut
End If
If LoggingState = True Then
Print #1, Now & " Connecting with this information:"
Print #1, " URL: " & FtpUrl
Print #1, " Username: " & Username
Print #1, " Password: " & PassWord
Print #1, " Proxy: " & ProxyServer & ":" & ProxyPort
End If



Inet1.Execute , "DIR"
Do While Inet1.StillExecuting
DoEvents
Loop


Exit Sub
LocalError:
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If
Inet1.Cancel
RaiseEvent Error(Err)
End Sub


Public Sub GetFiles(strDir As String)
On Error GoTo LocalError
Dim i As Integer
For i = 1 To Files.Count
Files.Remove (1)
Next i

LastAction = bwListing
If LoggingState = True Then
Print #1, Now & " Listing files of: " & strDir
End If

Inet1.Execute , "DIR" & " " & strDir
Do While Inet1.StillExecuting
DoEvents
Loop
If LoggingState = True Then
Print #1, Now & " Response on listing files: " & Inet1.ResponseInfo
End If

Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If

End Sub


Private Sub Inet1_StateChanged(ByVal State As Integer)
On Error GoTo LocalError
Dim DirData As String
Dim tmpData As String
Dim bDone As Boolean
Dim strEntry As String
Dim i As Integer
Dim k As Integer
sResponseString = ""
lResponseCode = 0
If State = icResponseCompleted Then
Debug.Print "Response complete.."
If LastAction = bwListing Then
Do Until bDone = True
tmpData = Inet1.GetChunk(1024, icString)
DoEvents
If Len(tmpData) = 0 Then
bDone = True
Else
DirData = DirData & tmpData
End If
Loop


For i = 1 To Len(DirData) - 1
k = InStr(i, DirData, vbCrLf)
strEntry = Mid(DirData, i, k - i)
If Right(strEntry, 1) = "/" Then
strEntry = Left(strEntry, Len(strEntry) - 1) & "/"
End If
If Trim(strEntry) <> "" Then
Files.Add strEntry
End If
i = k + 1
DoEvents
Next i
If LoggingState = True Then
Print #1, Now & " Listing complete."
End If

LastAction = bwNothing
ElseIf LastAction = bwGetCurDir Then
CurDir = Inet1.GetChunk(10000, icString)
LastAction = bwNothing
ElseIf LastAction = bwGetResult Then
sResponseString = Inet1.GetChunk(10000, icString)
Debug.Print Trim(sResponseString)
LastAction = bwNothing
End If
ElseIf State = icError Then
Debug.Print "Error..."
sResponseString = Inet1.ResponseInfo
lResponseCode = CLng(Inet1.ResponseCode)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Inet1.ResponseCode) & "-" & Inet1.ResponseInfo
End If

ElseIf State = icResolvingHost Then
Debug.Print "Resolving host.."
If LoggingState = True Then
Print #1, Now & " Resolving host.."
End If
ElseIf State = icHostResolved Then
Debug.Print "Host resolved..."
If LoggingState = True Then
Print #1, Now & " Host resolved"
End If
ElseIf State = icConnecting Then
Debug.Print "Connecting..."
If LoggingState = True Then
Print #1, Now & " Connectiong..."
End If
ElseIf State = icConnected Then
Debug.Print "Connected..."
If LoggingState = True Then
Print #1, Now & " Connected"
End If
ElseIf State = icRequesting Then
Debug.Print "Requesting..."
If LoggingState = True Then
Print #1, Now & " Sending request..."
End If
ElseIf State = icRequestSent Then
Debug.Print "Request send..."
If LoggingState = True Then
Print #1, Now & " Request send"
End If
ElseIf State = icReceivingResponse Then
Debug.Print "Receiving response..."
If LoggingState = True Then
Print #1, Now & " Receiving data..."
End If

ElseIf State = icResponseReceived Then
Debug.Print "response received"
If LoggingState = True Then
Print #1, Now & " Response received"
End If
ElseIf State = icDisconnecting Then
If LoggingState = True Then
Print #1, Now & " Disconnecting.."
End If
ElseIf State = icDisconnected Then
If LoggingState = True Then
Print #1, Now & " Disconnected"
End If
End If

Exit Sub
LocalError:
RaiseEvent Error(Err)
If LoggingState = True Then
Print #1, Now & " Error: " & CStr(Err) & "-" & Error(Err)
End If

End Sub

zcm123 2004-12-19
  • 打赏
  • 举报
回复
现学来不及了,你们有没有现成的模块阿?可以上下载,并且显示进度就可以了,谢谢各位了~
aohan 2004-12-19
  • 打赏
  • 举报
回复
打VB FTP 就会发现很多
jilong4 2004-12-19
  • 打赏
  • 举报
回复
帮你顶
Programer_Zjw 2004-12-19
  • 打赏
  • 举报
回复
现在原程序多的是, vb资源大全里就有啊,
online 2004-12-19
  • 打赏
  • 举报
回复
vbgood上有
你找找
homezj 2004-12-18
  • 打赏
  • 举报
回复
问这么多问题,估计你对FTP协议还没什么谱,那你就用错控件了,换Microsoft Internet Transfer,它专门有FTP支持,不用你了解很多FTP协议细节。
TechnoFantasy 2004-12-18
  • 打赏
  • 举报
回复
http://www.acky.net/vb/vbtcp/
这里有很多利用winsock的FTP代码,至于要实现你的所有功能,你需要对FTP协议(好像是RFC821)有了解。
zcm123 2004-12-18
  • 打赏
  • 举报
回复
Microsoft Internet Transfer那个上传的进度如何实现阿~~~~~~~~~ 呵呵
zcm123 2004-12-18
  • 打赏
  • 举报
回复
呵呵 说实话 确实我对这方面的知识比较匮乏^^!


Microsoft Internet Transfer 的 如何实现呢?

谁能发些 实例阿~~
===========================================================

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧