|
-
Sep 12th, 2000, 08:53 PM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 12th, 2000, 09:28 PM
#2
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
-
Sep 13th, 2000, 01:49 AM
#3
Thread Starter
Hyperactive Member
How amazing it is to learn...
Now, that ReturnStr variable is simply dimmed as a string, right?
Thanks
-
Sep 13th, 2000, 03:25 AM
#4
New Member
-
Sep 13th, 2000, 10:42 AM
#5
Thread Starter
Hyperactive Member
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.
-
Sep 13th, 2000, 01:41 PM
#6
Frenzied Member
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.
-
Sep 13th, 2000, 08:07 PM
#7
Thread Starter
Hyperactive Member
Hey job, thanks for the help but it just won't work. Have you tried it?
The text1.text remains "".
Can this be done?!
-
Sep 13th, 2000, 08:39 PM
#8
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
-
Sep 13th, 2000, 09:01 PM
#9
Fanatic Member
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
-
Sep 13th, 2000, 09:04 PM
#10
Thread Starter
Hyperactive Member
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.
-
Sep 13th, 2000, 09:54 PM
#11
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?
-
Sep 13th, 2000, 09:59 PM
#12
Thread Starter
Hyperactive Member
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?
-
Sep 13th, 2000, 10:35 PM
#13
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
-
Sep 14th, 2000, 07:52 AM
#14
Thread Starter
Hyperactive Member
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 =)
-
Sep 15th, 2000, 10:13 AM
#15
Thread Starter
Hyperactive Member
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.
-
Sep 15th, 2000, 12:50 PM
#16
Fanatic Member
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
-
Sep 15th, 2000, 01:40 PM
#17
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
-
Sep 15th, 2000, 02:05 PM
#18
Fanatic Member
Even though winsock is a longer way, i would suggest you use Matthew's code...b/c inet is not that reliable.
D!m
-
Sep 19th, 2000, 09:12 AM
#19
Thread Starter
Hyperactive Member
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.
-
Sep 19th, 2000, 10:35 AM
#20
Thread Starter
Hyperactive Member
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
-
Sep 19th, 2000, 01:44 PM
#21
Krass, here are a list of examples from http://www.planet-source-code.com of using Winsock to make a FTP.
-
Sep 19th, 2000, 02:00 PM
#22
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|