Avatar billede brian Nybegynder
19. marts 2000 - 11:50 Der er 15 kommentarer og
1 løsning

Opdatering af IP.

Nogle der kender en stump kode der kan finde min IP, sætte den ind i et HTML dokument og uploade den ?



Avatar billede overload.dk Nybegynder
19. marts 2000 - 16:38 #1
Ikke umiddelbart en stump tror jeg :)

Kig på http://planet-source-code.com

- der finder du sikkert rigelige af scripts der kan uploade, finde ip, og sammensætte HTML dokumenter - de skal bare lige strikkes sammen!

- mere kan jeg desværre ikke hjælpe. :(
- men god fornøjelse med programmeringen. :)

PS: jeg svare (sæt nu du fandt det du ledte efter :)
Avatar billede brian Nybegynder
19. marts 2000 - 16:44 #2
Tak for svaret, men jeg har nu kigget uden held. Det kan selvfølgelig være at det er fordi jeg ikke umiddelbart kan se hvordan jeg skal kæde det sammen.

Ip-adressen er ikke et problem, men få den sat ind i et HTML dokument og derefter få det uploadet til min udbyder volder mig alvorlige problemer. Jeg kunne jo selvfølgelig bare gøre det manuelt, men..........
Avatar billede webster Nybegynder
19. marts 2000 - 16:44 #3
Du kan i hvert fald finde din ip med winsock1.localip. At generere et html dokument er ikke så svært. Åben en fil for output og skriv så html koden i den.
Når du siger uploade, hvad mener du så, at sende den til en ftp server eller hvad?
Avatar billede webster Nybegynder
19. marts 2000 - 16:47 #4
Nu skriver du at du har problemer med det med html. Et eksempel:
Open "IP.htm" for output as #1
write #1, "<html><body bgcolor=....."
write #1, "Min IP er: & winsock1.localIP
write #1, "</body></html>"
Avatar billede brian Nybegynder
19. marts 2000 - 16:48 #5
jep. Når min ip er sat i et html dokument skal programmet uploade dokumentet til min udbyder.
Avatar billede overload.dk Nybegynder
19. marts 2000 - 17:37 #6
Okay, jeg prøver at kigge på det senere.
Avatar billede webster Nybegynder
19. marts 2000 - 19:17 #7
Vel. Jeg kommer selv til at skulle bruge en lign. funktion inden så længe, så jeg bikser lige en kontrol sammen der kan uploade(og for den sags skyld downloade). Hvis jeg lige får din e-mail sender jeg den til dig så snart den er færdig. Det regner jeg med at den er inden i morgen aften.
Avatar billede webster Nybegynder
19. marts 2000 - 20:31 #8
Nå, der kom jeg vidst til at love lidt for meget. Jeg er bange for at jeg ikke kan nå at lave en sådan kontrol til i morgen, da jeg først skal være færdig med en udbygget list control. Prøv i stedet at se på classen på: http://216.5.163.42/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=5656

Den kan godt nok kun uploade filer, men i første omgang har du vel heller ikke brug for andet.
Avatar billede overload.dk Nybegynder
19. marts 2000 - 22:59 #9
hvis Webster kigger på det, vil jeg lade ham gøre det. Han er sikkert også bedre til det end mig :)
Avatar billede brian Nybegynder
20. marts 2000 - 08:56 #10
webster > meget brugbar kode, men lige for at være lidt besværlig - jeg skulle meget gerne uploade filen til et bestemt bibliotek på serveren og det syntes der ikke lige umiddelbart at være mulighed for ?
Avatar billede webster Nybegynder
20. marts 2000 - 12:21 #11
Kigger på det så snart jeg kommer hjem.
Overload.dk > det skal du ikke være så sikker på. Jeg er bare blevet helt vild med at lave controller på det sidste.
Avatar billede webster Nybegynder
20. marts 2000 - 12:56 #12
Nå. Som altid gør jeg noget andet end jeg siger. Jeg kom lige i tanke om, at der egentligt ikke er nogen grund til at lave en control der allerede findes. Nemlig Microsoft Internet Transfer Control. Med den skal man "bare" kunne en lille smule Ftp kommandoer, så glider alt. Jeg har prøvet at lave et eksempel. Jeg har ikke VB her på skolen, så der er ingen garanti for at det virker:
Public Sub SendFiles(ByVal Brugernavn As String, ByVal Password As String, ByVal ServerAdress As String, ByVal FilSti As String, ByVal ServerBibliotek As String)

'Disse to linier stopper eventuelle operationer, og lukker en evt. eksisterende forbindelse
Inet1.Cancel
Inet1.Execute , "CLOSE"

'Derefter opretter vi forbindelsen
Inet1.AccessType = icUseDefault
Inet1.URL = ServerAdress
Inet1.UserName = Brugernavn
Inet1.Password = Password
Inet1.RequestTimeout = 30

Inet1.Execute , "DIR"

'Nu skal vi så til at sende filen
Inet1.Execute , "PUT " & FilSti & " " & Serveradresse & ServerBibliotek

'Derefter lukker vi efter os igen
Inet1.Cancel
Inet1.Execute , "CLOSE"

End Sub
Avatar billede pallepophår Nybegynder
24. marts 2000 - 00:16 #13
Undskyld jeg blander mig - men prøv lige at checke din mail Brian - jeg er sikker på at du især skal bruge det til at tjene lidt kroner ????

Webster > det virker ikke helt efter hensigten, jeg troede ellers at jeg kunne luskelytte mig til et godt tip, men....nej!!!!
Avatar billede webster Nybegynder
24. marts 2000 - 12:29 #14
Øh.
> Pallepophår, hvad mener du med at han skal tjene på det?
Avatar billede brian Nybegynder
24. marts 2000 - 14:04 #15
PallePop > lad nu være med et pjat.

Webster > han mener, at jeg har Alladvantage kørende, men blander 2 spørgsmål sammen.
Avatar billede webster Nybegynder
25. marts 2000 - 10:29 #16
Alladvantage siger mig ikke lige så meget, men her er lidt mere om FTP med InetKontrollen i tilfælde af at du ikke har fundet ud af det endnu (Ved godt det er lidt meget at poste).

Introduction

Well, the final part of the Inet series has finally arrived! This week, I will take you through looking at using the Inet control to perform FTP operations. We will look at connecting to an FTP server, getting directory and file listings, removing files on the server, uploading and downloading files and other FTP tasks. At the end of this article you will also see a downloadable project that contains all the code from this article, as well as a class module that includes all the API declares for the Inet FTP commands (ie you don't need to control)

Get connected

Lets start off with the basics first: connecting.

The first thing we need to do is to set the Protocol property of the Inet control to icFTP. We also need to specify a server address (in the form of a URL) and a username and password to login. If the FTP site doesn't require a username and password, then you can just leave them blank. All of these properties can be set using the Property Page in the IDE, or you can set them at run time:

With Inet1
    .Cancel
    .Protocol = icFTP
    .URL = "localhost"
    .Username = ""
    .Password = ""
End With

You may have noticed that there is no specific Connect command in the Inet control, so what we have to do is use the Execute command, which allows us to execute a special FTP command.

(If you have ever used DOS before then you will be familiar with some of the commands used)

Your wish is my command

Just think back to the last time that you used an FTP program. What is the first thing it does after connecting? Show a list of all the directories and files in the default directory. This can be done using a DIR command and some clever stuff in the Inet's StateChanged event.

Here are some of the commands that you will be using when you FTP into a server:

CD - Change directory
CDUP - Change to the parent directory. The same as "CD .."
DELETE - Deltes a file
DIR - Retrieves the current directory listing
GET - Retrieves a file
MKDIR - Makes a new directory
PUT - Uploads a file
PWD - Sends a password
QUIT - Ends an FTP session
RECV - The same as GET
RENAME - Renames a file
RMDIR - Deletes a directory
SEND - Same as PUT
SIZE - Retrieves the size of a file

This is all very well and true, but how do I actually connect and get the contents of the root directory? Lets find out.

Navigating the server

Well, in the Inet's StateChanged event, we need to monitor when data comes in and then do some trickery to get what the server is sending. Firstly, it is a good idea to store the current command (e.g. GET) as a module level variable. This way all the procedures can access it and we know what we are currently doing.

For example, if we wanted a list of directories, then we would set our variable to DIR, and then use the Execute method. This way when we are in the StateChanged event, a completely different procedure, we still know what the last command was.

The StateChanged event procedure provides us with one parameter, State. We can use a Select Case statement to determine what is currently going on. Now, the server only sends back data after the state of icResponseCompleted, so we need to stick in another Select Case statement to find out what command we are executing.

Lets quickly recap on the code. Here is what we have so far in the StateChanged event:

Private Sub Inet1_StateChanged(ByVal State As Integer)

    Select Case State
    Case icResponseCompleted
        Select Case strCmd
        Case "DIR"
        End Select
    End Select
End Sub

OK. As the StateChanged event only passes the State parameter, we need to manually get the data that is being sent by the server. We do this using the GetChunk method. Because of the way things are, we can only get 512 characters at a time, so we need to set-up a loop that will make sure that we get all the data. It looks something like this:

Do
    strNewData = Inet1.GetChunk(512,icString)
    DoEvents
    If Len(strData) = 0 Then Exit Do
    strData = strData & strNewData
Loop

Notice the use of DoEvents. This is very important because we must give the server time to sort itself out otherwise we will run into a whole load of problems.

If you are currently testing out this code, you will notice that the contents of strData are not exactly 'user friendly' at the moment. We still need to go through and format the data, for whatever control we are going to load it into. Each file and directory is in the string and at the end of each one, a vbCrlf character can be found. This makes it easy to parse out all the different items using some of VBs great string functions:

Do While Len(strData)
    intPos = Instr(strData,vbCrlf)
    If intPos Then
    strItem = Left$(strData, intPos - 1)
    strData = Mid$(strData, intPos + 2)
    Else
    strItem = strData
    strData = ""
    End If
Loop

But how do we know the difference between a file and a directory? Well, fortunately all directories come with a trailing /, so we can look for that when we want to do something with the item:

strItem = lstDir.List(lstDir.ListIndex)
If strItem = ".." Or Right$(strItem,1) = "/" Then
    DoEvents
    If strItem = ".." Then
    strCmd = "CDUP"
    Inet1.Execute ,strCmd
    Else
    strCmd = "CD " & Left$(strItem, Len(strItem) -1)
    Inet1.Execute ,strCmd
    End If
End If

OK. So now we have a list of directories. The next thing we are going to learn, is how to upload files.

Files & Directories

This starts to get a bit simpler, because it is mainly a case of using the Execute command.

The syntax of the PUT command is as follows:

PUT localfile, remotefile

Here is a sample:

Inet1.Execute ,"PUT c:\myfile.txt /myfile.txt"
(Remember to include that preceeding '/')

To download a file, use the GET command:

GET remotefile, localfile
Inet1.Execute ,"GET myfile.txt c:\myfile.txt"

To delete a file, you need to use the DELETE command:

DELETE remotefile
Inet1.Execute ,"DELETE myfile.txt"

And finally, renaming a file can be done using, yes, you guessed it the RENAME command:

RENAME oldname,newname
Inet1.Execute ,"RENAME myfile.txt mynewfile.txt"

OK. Now that we have finsihed with files, lets move onto directories.

When handling directories, we need to add and delete them. For DOS gurus, this should be like the good old days! Simply use the MKDIR and RMDIR to make and remove directories. You should be aware of the syntax for both of these commands:

Pretty simple, but you must remember to place the / in at the correct places, otherwise you will have problems.


Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester