OpenFTP baut keine FTP-Verbindung auf
Verfasst: 05.02.2010 13:12
Hi,
ich habe schon die Suche genutzt aber nichts gefunden, was auf mich zutrifft.
Es ist folgendes:
Ich schreibe gerade versuchsweise einen konsolenbasierten FTP-Client. An der Stelle wo die Verbindung aufgebaut werden soll, passiert dies jedoch nicht. Ich poste einfach mal den Code:
Vielleicht weiß jemand was das Problem ist? Es geht um die Prozedur establishConnection().
P.S.: Ist bestimmt nicht der schönte Code, aber wenn jemand weiß wie man das ganze eleganter lösen könnte bin ich offen
ich habe schon die Suche genutzt aber nichts gefunden, was auf mich zutrifft.
Es ist folgendes:
Ich schreibe gerade versuchsweise einen konsolenbasierten FTP-Client. An der Stelle wo die Verbindung aufgebaut werden soll, passiert dies jedoch nicht. Ich poste einfach mal den Code:
Code: Alles auswählen
InitNetwork()
Declare establishConnection()
Declare checkConnections()
Declare closeConnection()
Structure connection
id.l
adress.s
user.s
pass.s
port.l
EndStructure
NewList connections.connection()
OpenConsole()
EnableGraphicalConsole(1)
Procedure mainMenu()
Shared connections()
ClearConsole()
PrintN("sFTPc-Main Menu//")
PrintN("1 - Open FTP Connection")
PrintN("2 - Close FTP Connection")
PrintN("3 - Check connections")
PrintN("4 - Quit")
PrintN("")
If ListSize(connections()) > 0
FirstElement(connections())
For k = 1 To ListSize(connections())
PrintN("Connection number: "+Str(connections()\id))
PrintN("Adress: "+connections()\adress)
PrintN("Username: "+connections()\user)
PrintN("")
NextElement(connections())
Next
Else
PrintN("There are currenty no established connections.")
EndIf
Print("Choose: ")
Select Val(Input())
Case 1
establishConnection()
Case 2
closeConnection()
Case 3
checkConnections()
Case 4
End
Default
PrintN("Not a valid option!")
Print("Push enter.")
mainMenu()
EndSelect
EndProcedure
Procedure establishConnection()
Shared connection, connections()
*newElement.connection = AddElement(connections())
ClearConsole()
*newElement\id = ListSize(connections())
Print("URL or IP: ")
*newElement\adress = Input()
Print("Username: ")
*newElement\user = Input()
Print("Password: ")
*newElement\pass = Input()
Print("Port (default is 21): ")
*newElement\port = Val(Input())
If *newElement\port = 0
*newElement\port = 21
EndIf
If 0 = OpenFTP(*newElement\id,*newElement\adress,*newElement\user,*newElement\pass)
PrintN("Could not open FTP-connection!")
Print("Push enter.")
Input()
EndIf
mainMenu()
EndProcedure
Procedure checkConnections()
Shared connections()
ClearConsole()
If ListSize(connections()) > 0
FirstElement(connections())
For k = 1 To ListSize(connections())
PrintN("Connection number: "+Str(connections()\id))
PrintN("Adress: "+connections()\adress)
PrintN("Username: "+connections()\user)
If 0 = CheckFTPConnection(connections()\id)
PrintN("Disconnected!")
Else
PrintN("OK!")
EndIf
NextElement(connections())
Next
Else
PrintN("There are currenty no established connections.")
EndIf
Print("Push enter.")
Input()
mainMenu()
EndProcedure
Procedure closeConnection()
Shared connections()
ClearConsole()
If ListSize(connections()) > 0
FirstElement(connections())
For k = 1 To ListSize(connections())
PrintN("Connection number: "+Str(connections()\id))
PrintN("Adress: "+connections()\adress)
PrintN("Username: "+connections()\user)
PrintN("")
NextElement(connections())
Next
Else
PrintN("There are currenty no established connections.")
Print("Push enter.")
Input()
mainMenu()
EndIf
Print("Choose Connection to close: ")
n = Val(Input())
If n <= 0 Or n > ListSize(connections())
PrintN("Not a valid value!")
Print("Push enter.")
Input()
mainMenu()
EndIf
CloseFTP(n)
SelectElement(connections(), n-1)
DeleteElement(connections(),1)
mainMenu()
EndProcedure
mainMenu()
P.S.: Ist bestimmt nicht der schönte Code, aber wenn jemand weiß wie man das ganze eleganter lösen könnte bin ich offen
