Results 1 to 22 of 22

Thread: Downloading a file with the internet transfer protocol

  1. #1

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    I am using the Internet Transfer Protocol to connect to an FTP. Could someone tell me the syntax to download a text file NOT TO THE HARD DISK but to a string variable or any other kind of container. I need it to be unreadable by the user.

    Must I use .OPENURL? Thanks.
    Chris

  2. #2
    Guest
    Try this:

    Code:
    Private Sub Command1_Click()
    RichTextBox1.Text = Inet1.OpenURL("http://forums.vb-world.net", icString)
    ReturnStr = Inet1.GetChunk(2048, icString)
    Do While Len(ReturnStr) <> 0
        DoEvents
        RichTextBox1.Text = RichTextBox1.Text & ReturnStr
        ReturnStr = Inet1.GetChunk(2048, icString)
    Loop
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    How amazing it is to learn...

    Now, that ReturnStr variable is simply dimmed as a string, right?

    Thanks
    Chris

  4. #4
    New Member
    Join Date
    Aug 2000
    Posts
    4
    Very nice tip! Thanx!

  5. #5

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    Matthew, your code example works for getting the text of a web page. Now what would I do to get a text file's content?

    Here's what I tried instead:

    Text1.Text = Inet1.OpenURL("ftp://vb:[email protected]/Subscribers.txt", icString)

    This will simply empty the Text1 textbox.

    Thanks.
    Chris

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Use it like this: first set the url, then the password then the username.

    Code:
    'From the VB helpfile.
    Inet1.URL = "FTP://24.200.146.67/Subscribers.txt"
    Inet1.Password = "vb"
    Inet1.UserName = "vb"
    Text1.Text = Inet1.OpenURL
    If that didn't work also set
    Code:
    Inet1.Protocol = icFTP
    Hope that helped...

    [Edited by Jop on 09-13-2000 at 02:49 PM]
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    Hey job, thanks for the help but it just won't work. Have you tried it?

    The text1.text remains "".

    Can this be done?!
    Chris

  8. #8
    Guest
    I think I know what you want: the header information.

    Code:
    Private Sub Inet1_StateChanged(ByVal State As Integer)
    On Error Resume Next
    Select Case State
    Case 3
    Timer1.Enabled = True
    End Select
    End Sub
    
    Private Sub Timer1_Timer()
    On Error Resume Next
    Dim h
    If Inet1.StillExecuting = False Then
    h = Inet1.GetHeader
    If Not h = "" Then
    Richtextbox1.Text =  h
    Timer1.Enabled = False
    Richtextbox1.Enabled = True
    Inet1.Cancel
    End If
    End If
    End Sub

  9. #9
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    How about d/l the file, load it into the string and then deleting it.
    Code:
    With Inet1
        .Cancel
        .Protocol = icFTP
        .url = "123.123.123.123"
        .UserName = "me"
        .Password = "xxxx"
    End With
    Inet1.Execute , "Get test.txt C:\test.txt"
    Dim temp As String
    Open FileName For Input As #F
       temp = Input$(LOF(F), F)
    Close #F
    Kill "C:\test.txt"

    Hope that helps,
    D!m

    Dim

  10. #10

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    Dim, I wanted to avoid downloading the file because the user could find a way to view its content. Thanks anyway!

    Matthew, thanks for your help...... header information? Doesn't sound familiar to me.. This will give me the content of the text file?? Anyway I'm gonna try it out!

    Thanks.
    Chris

  11. #11
    Guest
    The header from http://www.vb-world.net looks like this:

    HTTP/1.1 200 OK
    Date: Thu, 14 Sep 2000 02:50:20 GMT
    Server: Apache/1.3.9 (Unix) PHP/3.0.12
    Keep-Alive: timeout=15, max=100
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/html


    Which displays the contents. Is that what you wanted?


  12. #12

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    Actually I am using the ITC to connect to an FTP. On this FTP there's a textfile called Hello.txt. I need the textfile's content in a variable.

    If possible I want to avoid, like Dim suggested, to download the file on the HD first.

    Now can this be done with your method?
    Chris

  13. #13
    Guest
    You want to get the source of an html page and put it in a text file?

    Code:
    Private Sub Command1_Click()
    RichTextBox1.Text = Inet1.OpenURL("http://forums.vb-world.net", icString)
    ReturnStr = Inet1.GetChunk(2048, icString)
    Do While Len(ReturnStr) <> 0
        DoEvents
        RichTextBox1.Text = RichTextBox1.Text & ReturnStr
        ReturnStr = Inet1.GetChunk(2048, icString)
    Loop
    Open "MyFile" For Output As #1
        Print #1, ReturnStr 
    Close #1
    End Sub

  14. #14

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    Not exactly, try reading my last post one more time.

    Like I said, there's a file on an ftp that's called Hello.txt. Hello.txt contains the following text: "Hello world".

    With ITC, I want my application to download the file Hello.txt BUT in a string variable, not on the hard disk. In other words, I want the content "Hello world" in a string variable, without actually downloading the file on the hard disk first.

    I hope I made it clear this time =)
    Chris

  15. #15

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    Well, since I couldn't find a way to do exactly what I want, I will first download the file to the hard disk, like Dim suggested.

    Dim, I have a few questions. I would like to know how big a text file can be handled by a string variable? For a big text would there be any memory loss? Is there any other variable to do the work?

    I believe such a text file should not go over 100k tho.

    Thanks.
    Chris

  16. #16
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    I don't see a problem with memory loss...what will happen is the whole storing process would take just as lonmg as it would take to download the file. You could split the file up into diff strings and then combine them into one...but that would be more complex than storing it as one string after all it's only text so it shouldn't take too long to transfer.

    Gl,
    D!m
    Dim

  17. #17
    Guest
    How about using Winsock to do it?

    Code:
    Dim TotalBytes as Long 
    Dim TempBytes as Long 
    Dim DownloadSpeed as Integer 
    
    Private Sub Form_Load() 
    DownloadSpeed = 0 
    TempBytes = 0 
    TotalBytes = 0 
    Text1.text = ""
    DownloadTimer.Enabled = False 
    DownloadTimer.Interval = 1000 
    End Sub
    
    Private Sub CmdConnect_Click()
    Winsock1.Connect "ftp://ftp.ftpsite.com", 80 
    End Sub
    
    Private Sub CmdDownload_Click()
    Me.Caption = "Connected to: " & Winsock1.RemoteHostIP 
    Winsock1.SendData "GET /" & File.txt & " HTTP/1.0" & vbcrlf & vbcrlf
    DownloadTimer.Enabled = True
    End Sub
    
    
    Private Sub Winsock1_DataArrival(bytes as long) 
    TempBytes = bytes 
    TotalBytes = TotalBytes + Int(bytes) 
    Me.Caption = "Downloading: " & TotalBytes " bytes complete. Speed: " & DownloadSpeed 
    Winsock1.GetData TempStr, VbString 
    Text1.Text = Text1.Text & VbString 
    End Sub 
    
    
    Private Sub Winsock1_Close() 
    Me.Caption = "Download Complete! " & TotalBytes & " were downloaded." 
    End Sub 
    
    Private Sub CmdExit_Click()
    Unload Me
    Set form1 = Nothing
    End
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Unload Me
    Set form1 = Nothing
    End
    End Sub
    
    Private Sub DownloadTimer_Timer()
    'Timer 
    DownloadSpeed = Int(TempBytes / 1024) 
    End Sub

  18. #18
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Even though winsock is a longer way, i would suggest you use Matthew's code...b/c inet is not that reliable.


    D!m
    Dim

  19. #19

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    Well, Matthew Gates, this code sounds fine! I am gonna try it.

    I got a question: before downloading a file from the ftp, I want to know its size (to inform the user). Can this be done? Thank you.
    Chris

  20. #20

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489
    I am having some problems using Winsock and I really hope one of you can help me.

    Here is the code you suggested:
    Winsock1.Connect "ftp://ftp.ftpsite.com", 80

    I tried:
    Winsock1.connect "ftp://bla:[email protected]", 21
    "bla" being my login and password. Unfortunately, it won't do anything when executing this line of code. I can see it's not even connecting to my ftp.

    I also tried:
    .RemostHost = "24.200.146.43"
    .RemotePort = "21"
    .Connect
    But then how would I set the login and password? Adding it to the .RemoteHost won't make it work. But at least, that way, it tried connecting to the ftp correctly.

    Any help appreciated

    Chris

  21. #21
    Guest
    Krass, here are a list of examples from http://www.planet-source-code.com of using Winsock to make a FTP.

  22. #22
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425
    Although many people have heard this before, check out http://www.dart.com. They have made a brilliant FTP control.

Posting Permissions

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



Click Here to Expand Forum to Full Width