diff --git a/server/server/connection.go b/server/server/connection.go index b248138..8c50d31 100644 --- a/server/server/connection.go +++ b/server/server/connection.go @@ -6,6 +6,8 @@ import ( "io" "log" "net" + + "github.com/spf13/viper" ) // DataBufferSize the maximum size of the data buffer. @@ -83,3 +85,35 @@ func HandleConnection(client Client) { // Client has left. log.Println(client.Connection().RemoteAddr(), "has disconnected.") } + +func StartFtpServer() { + InitializedConfiguration() + + Addr := viper.GetString("address") + Port := viper.GetString("port") + DirDepth := viper.GetInt("maxDirDepth") + + // Start the server + listener, err := net.Listen("tcp", Addr+":"+Port) + if err != nil { + log.Fatal(err) + } + + log.Println("Hello world!") + log.Println("Ftp server running on:", Addr, "port", Port) + + for { + + conn, err := listener.Accept() + if err != nil { + log.Print(err) + continue + } + + client := FTPClient{} + client.SetStack(MakeStringStack(DirDepth)) + client.SetConnection(conn) + + go HandleConnection(&client) + } +} diff --git a/server/simplFTP.go b/server/simplFTP.go index 76e0a4b..d743fed 100644 --- a/server/simplFTP.go +++ b/server/simplFTP.go @@ -1,41 +1,9 @@ package main import ( - "log" - "net" - "github.com/metonimie/simpleFTP/server/server" - "github.com/spf13/viper" ) func main() { - server.InitializedConfiguration() - - Addr := viper.GetString("address") - Port := viper.GetString("port") - DirDepth := viper.GetInt("maxDirDepth") - - // Start the server - listener, err := net.Listen("tcp", Addr+":"+Port) - if err != nil { - log.Fatal(err) - } - - log.Println("Hello world!") - log.Println("Running on:", Addr, "port", Port) - - for { - - conn, err := listener.Accept() - if err != nil { - log.Print(err) - continue - } - - client := server.FTPClient{} - client.SetStack(server.MakeStringStack(DirDepth)) - client.SetConnection(conn) - - go server.HandleConnection(&client) - } + server.StartFtpServer() }