PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2008 download file-VBForums
Results 1 to 16 of 16

Thread: download file

  1. #1

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    download file

    ok there is my problem .. im trying to download a file from an url :
    first i go to this website : http://www.flvto.com/
    then i convert and at the end there is a "direct link" label. I get this label's url then i try download that throught an app .. but the file at the end only have 0kbs .. like if only the File was created without nothing downloaded .. please help there is my download code :

    Code:
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            Dim request As HttpWebRequest = _
        DirectCast(System.Net.HttpWebRequest.Create(TextBox1.Text), HttpWebRequest)
    
            request.Method = WebRequestMethods.Http.Head
            'request.SendChunked = True
            'request.Headers.Add("Translate: f")
            'client.DownloadFileAsync(New Uri(TextBox1.Text), TextBox2.Text)
            Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            Dim destination As String = TextBox2.Text
    
            'Create the buffer for storing the bytes read from the server
            Dim byteTransferRate As Integer = 4096 '4096 bytes = 4 KB
            Dim bytes(byteTransferRate - 1) As Byte
            Dim bytesRead As Integer = 0 'Indicates how many bytes were read 
            Dim totalBytesRead As Long = 0 'Indicates how many total bytes were read
            Dim contentLength As Long = 0 'Indicates the length of the file being downloaded
    
            'Read the content length
            'contentLength = CLng(response.GetResponseHeader("Content-Length"))
    
            'Create a new file to write the downloaded data to
            Dim fs As New IO.FileStream(destination, IO.FileMode.Create, _
                   IO.FileAccess.Write)
    
            'Get the stream from the server
            Dim s As IO.Stream = response.GetResponseStream()
    
            Do
                'Read from the stream
                bytesRead = s.Read(bytes, 0, bytes.Length)
    
                If bytesRead > 0 Then
    
                    totalBytesRead += bytesRead
    
                    'Write to file
                    fs.Write(bytes, 0, bytesRead)
    
                End If
    
            Loop While bytesRead > 0
    
            'Close streams
            s.Close()
            s.Dispose()
            s = Nothing
    
            fs.Close()
            fs.Dispose()
            fs = Nothing
    
            'Close the response
            response.Close()
            response = Nothing
            If totalBytesRead <> contentLength Then
    
                MessageBox.Show("The downloaded file did not download successfully, " & _
                    "because the length of the downloaded file " & _
                    "does not match the length of the file on the remote site.", _
                    "Download File Validation Failed", _
                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
    
            Else 'totalBytesRead = contentLength
    
                MessageBox.Show("The file has downloaded successfully!", "Download Complete", _
                    MessageBoxButtons.OK, MessageBoxIcon.Information)
    
            End If
        End Sub

  2. #2

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    and even with downloadfileasyinc it doesnt work .. thanks for help

  3. #3
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: download file

    Um maybe completely irrelevant to your question, but:
    You can use one of the so many conversion tools around.

    Almost every Freeware conversion program I have seen uses "ffmpeg.exe". It can convert virtually any format from and to other formats.

    http://www.ffmpeg.org/
    http://ffmpeg.zeranoe.com/builds/

    To your question.

    First of all, have you verified you can download the file at all? Copy the download link you placed in TextBox1 into a regular webbrowser and navigate. If no download popup emerges you need to work on your URL.

    And the only way it could end up completely empty is if 0 bytes are read. Depending on the connection, may be some sort of delay before bytes are read?

    If client.DownloadFileAsync fails as well, it is probably an URL error. Also note that you may need certain headers set for your request to be successful.

  4. #4

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    copied and pasted the directlink url to an other webpage , a download thing poped up . i cant figure why it keep failing

  5. #5

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    oh wait ur right , i tried though a webbbrowser and i cant navigate to the url

  6. #6

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    then how i can make it download it??

  7. #7

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    you talked abt header? maybe there is a solution though that??

  8. #8

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    maybe if i look thought webpage html stuff .. but how set it in vb?? i mean like to request in that way.

  9. #9
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: download file

    Headers are set by the webbrowser, it contains information of what you did previously and is usually set by the return header of a previous request.

    It gets pretty complicated from there. If you believe it's an header issue, you can download the "Tamper Data" Firefox plugin. With it you can inspect requests made to websites and read the "post data", and the headers returned.

    Do everything as usual on the website, until you start to click the final download link. Start tampering, navigate and read the request parameters set for that request.

    https://addons.mozilla.org/en-US/fir...n/tamper-data/

  10. #10

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    hope will work ill try that and hit you back Thanks for answer

  11. #11

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    added all headers .. still 0 kb x-x maybe i did something wrong?

  12. #12

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    there is my code :

    vb Code:
    1. Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    2.         client.Headers.Add(HttpRequestHeader.Host, "www.flvto.com")
    3.         client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0")
    4.         client.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
    5.         client.Headers.Add(HttpRequestHeader.AcceptLanguage, "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3")
    6.         client.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate")
    7.         client.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
    8.         client.Headers.Add(HttpRequestHeader.Connection, "keep-alive")
    9.         client.Headers.Add(HttpRequestHeader.Referer, TextBox1.Text)
    10.         client.Headers.Add(HttpRequestHeader.Cookie, "lang=en; user_lang=en; __utma=84844110.1954461035.1310340112.1310340112.1310340526.2; __utmb=84844110.1.10.1310340526; __utmz=84844110.1310340112.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=usrjc16mcj9gm06ta2juieort6; __utmc=84844110")
    11.  
    12.         client.DownloadFileAsync(New Uri(TextBox1.Text), TextBox2.Text)
    13.  
    14.  
    15.  
    16.  
    17.     End Sub

  13. #13

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    is there a way to get the location (see picture) from a webpage with client??(webclient) or webbrowser.document.getelementby .. (something)



    link for image : http://img233.imageshack.us/img233/2701/tabof.png
    Last edited by ibennz; Jul 10th, 2011 at 10:20 PM. Reason: image

  14. #14

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    anyone ..?

  15. #15
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: download file

    If it is visible in the HTML you can. If it is part of a flash/java application, I doubt. I hope someone else can help around here; don't know much of cookies in requests, and you probably need one...

  16. #16

    Thread Starter
    Hyperactive Member ibennz's Avatar
    Join Date
    Aug 2010
    Posts
    282

    Re: download file

    well if someone can give me some hints , will be helpfull . Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width