|
-
Apr 3rd, 2000, 10:48 AM
#1
Is there a way to download a file off the internet using the winsock control? I can do it with the inet control but i dont really like that one alot because its hard to show the progress of the download.
-
Apr 3rd, 2000, 04:40 PM
#2
Lively Member
Add a winsock control to you form and a text box and use some code such as...
Winsock = SckSocket
Text = DownloadText
Text = FilenameText
Timer = DownloadTimer
'These go into Declarations on the form
Dim TotalBytes as Long
Dim TempBytes as Long
Dim DownloadSpeed as Integer
'Being main code
Private Sub Form_Load()
DownloadSpeed = 0
TempBytes = 0
TotalBytes = 0
DownloadText.Text = ""
DownloadTimer.Enabled = False
DownloadTimer.Interval = 1000
End Sub
Private Sub ConnectCmd_Click()
SckSocket.connect "www.webserver.com", 80
Me.Caption = "Connecting to host..."
End Sub
Private Sub SckSocket_Connect()
Me.Caption = "Connected to: " & SckSocket.RemoteHostIP
SckSocket.SendData "GET /" & FileNameTxt.Text & " HTTP/1.0" & vbcrlf & vbcrlf
DownloadTimer.Enabled = True
End Sub
Private Sub SckSocket_DataArrival(bytes as long)
TempBytes = bytes
TotalBytes = TotalBytes + Int(bytes)
Me.Caption = "Downloading: " & TotalBytes " bytes complete. Speed: " & DownloadSpeed
SckSocket.GetData TempStr, VbString
DownloadText.Text = DownloadText.Text & VbString
End Sub
Private Sub SckSocket_Close()
Me.Caption = "Download Complete! " & TotalBytes & " were downloaded."
End Sub
Private Sub DownloadTimer_Timer()
DownloadSpeed = Int(TempBytes / 1024)
End Sub
Make a form, add the above objects, run it
and put in the Text box for "FileNameText" something like..
/index.html
Note: That code was off the top of my head and has NOT been tested. Perhaps someone else can repost the code so that it supports Binary files and not just a html/text file.
Regards,
 Paul Rivoli 
---------------------
[email protected]
http://members.dingoblue.net.au/~privoli
-
Apr 4th, 2000, 07:28 AM
#3
yea it seems to work, but the data is not encoded, meaning it doesn't show the content, rather just the bits or bytes or some kinda crap in there, it works fine, but how would you go about transfering a whole file from internet to your harddrive?
-
Apr 4th, 2000, 12:34 PM
#4
How can i get the size of the file before downloading it? So i can use a progressbar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|