PDA

Click to See Complete Forum and Search --> : Winsock question


jonny bravo
Feb 17th, 2007, 12:51 AM
I want to download a picture using only winsock,
Is it possible to do?
If it isn't I want to download the "source code" of the picture, and save it as a picture file,
Is it possible to do?

XCustoms
Feb 17th, 2007, 04:35 AM
I Think Is Possible But I'm Not Sure How
I Will Try To Figure Out

If Someone Else Knows It Please Help Him
I Will Try To Make It

Jean.B
Feb 17th, 2007, 06:55 AM
if you want to download picture from web server, you need to send the http request for it, then the server will send you the reply and picture data, which you can save..

jonny bravo
Feb 17th, 2007, 07:07 AM
Yes I want to download the picture.
Can you explain me this in an example code?
For example, downloading this picture:
http://pc.co.il/_uploads/extraimg/gindis(1).jpg

the182guy
Feb 17th, 2007, 07:44 AM
You could use the URLDownloadToFile API. I've attatched a form that demos it. Here is the code:


Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Private Sub command1_click()

Dim errcode As Long
Dim url As String
Dim localFileName As String

'WHAT FILE TO DOWNLOAD?
url = "http://pc.co.il/_uploads/extraimg/gindis(1).jpg"
'WHERE TO SAVE IT?
localFileName = "c:\gindis(1).jpg"

errcode = URLDownloadToFile(0, url, localFileName, 0, 0)
If errcode = 0 Then
MsgBox "Download finished and saved to: " & localFileName
Else
MsgBox "Error while downloading"
End If

End Sub

Slyke
Feb 17th, 2007, 09:21 AM
Is there any way to get the file's size and a progress on how much is has downloaded?

the182guy
Feb 17th, 2007, 09:35 AM
How to get the filesize and show progress using URLDownloadToFile API (http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=64914&lngWId=1)

jonny bravo
Feb 17th, 2007, 09:37 AM
I am asking if can I download the file using Winsock and not any API's

the182guy
Feb 17th, 2007, 09:39 AM
Yes you can do it with Winsock, why don't you search. It's much more difficult using winsock though, you have to have a decent grasp of Winsock and the HTTP protocol. Far easier to do it with the API.

jonny bravo
Feb 18th, 2007, 02:15 PM
I know its much easier, but I need help with the winsock.
About searching, I have searche and have not found information to help me.

Al42
Feb 19th, 2007, 01:30 PM
You can download it with the Winsock control or you can download it and show progress. You might be able to download it with the Winsock control and show progress by subclassing the control, but using an API is a lot easier than subclassing.

jonny bravo
Feb 19th, 2007, 01:49 PM
never mind
I have found how to download throught winsock.