How to program an FTP client in C? [closed]

2020-07-27 15:59发布

问题:

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 7 years ago.

I have to program the code for a client who wants to transfer a file to a server, the protocol RCFTP. The operation should be: the client sends a request to save a portion of the file, the server will respond if you have received this piece without errors. If so, the client will still send pieces of the file until you have submitted all without errors. If a transmission error, the client must send back the piece of file failed.

Would know a little help to get started?

回答1:

  1. Investigate if you can use any pre-existing code, such as a library.
  2. Read up on sockets and try to implement the FTP protocol.
  3. Get back here when you have concrete questions and can show some code. :)


回答2:

At first, if you want to code an ftp client read really carefully this : RFC959.

To help you for the beginning, here is few steps you need to know (for sure, i won't describe everything, but it will probably help you) :

  1. Connect your socket (control socket) to your ftp server on the port 21.
  2. You will receive on your socket a message from the ftp server (code : 220).
  3. Then you send your login to the ftp server using the command USER and wait for confirmation (331)
  4. Then send your password using the command PASS and wait for confirmation that you are logged on the server (230).
  5. Now you can do some operation on the ftp.

To send file you have to use the passive mode :

  1. Send command PASV, you will get an answer that give you an IP address and a port (227), you will have to parse this message.
  2. Connect a second socket (a data socket) wit the given configuration.
  3. Use the command STOR on your control socket (to define the file you want to create on the server)
  4. Send data through the data socket and when you are done, close data socket.

Then leave your session using on the control socket the command QUIT.

It's clearly easy to code a simple ftp client if you are used to "sockets concept".



回答3:

Search for socket tutorials using your favourite internet search engine.

I found one here