![]() The trick to staying sane while debugging an FTP server is proper logging. For example, a PORT command is secretly sent before every get/RETR request. In addition, the client sends certain commands without the user’s direct intervention. ls is LIST, close is QUIT and get translates to RETR. cd in the client is sent to the server as CWD. ![]() Confusingly, however, the command names mandated by FTP don’t always match the commands you enter in the client to trigger them. The rest of ftp.Serve is no more complicated than a switch on the first word of the client request, command. ![]() Once handleConn returns, the goroutine ends. The loop is infinite, so Serve will keep checking for commands until some event (like the QUIT command) causes it to return, which in turn causes main.handleConn to return, closing the net.Conn we defered. To listen for incoming commands, we create a new bufio.Scanner against the ftp.Conn's underlying net.Conn. More on respond and FTP status codes shortly. The first thing we do upon entering Serve is to issue a 220 response to the client, letting it know the connection has been established successfully and that the server is ready to accept a user. I assume a basic knowledge of Go’s net package and goroutines, but it doesn’t get harder than that. My thanks to Github user Kdama for pointing me in the right direction. Unless you know the ins and outs of FTP already - its standard response codes and when to use them, how data connections are configured, and even how lines of text should be terminated - this challenge will get your blood pressure up.Īvoid giving yourself an aneurysm by following this step-by-step guide to building a simple FTP server of your own. It’s extremely prescriptive (it’s a networking protocol, after all). ![]() However, there’s complexity here that has nothing to do with how much Go you know - it comes from FTP itself. There’s no “right way” of doing it, you’re simply challenged to build the best solution you can with the knowledge you have. This is the type of large, freeform project that excites me. The server should interpret commands from each client such as cd to change directory, ls to list a directory, get to send the contents of a file, and close to close the connection. Working my way through the Go Bible - Donovan and Kernighan’s “The Go Programming Language” - I came upon a problem that both inspired and frustrated me.Įxercise 8.2: Implement a concurrent File Transfer Protocol (FTP) server. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |