FTP代写:CS159SocketProgrammingFTPServer


Introduction

这个需要代写的作业要求基于Linux Socket编程,实现一个 FTP Server
。需要支持常见的上传(put)、下载(get)和列表(ls)等命令。

Requirement

Your task is to create a very simple FTP server program using sockets.

  1. The server needs to be able to interpret the protocol commands, including: LIST, RETR, STOR
  2. The client should be a standard command line FTP client application (available on your OS). The application commands that should work from the client are:
    dir (or ls)
    get
    put
    Assume that the files to be transferred are text only (ASCII rather than
    binaries). There is no need to implement text X binary modes.

Part 1

This exercise makes use of the FTP protocol directly from a command line
application. You have probably used FTP before, but in a transparent way
(perhaps via a browser).
FTP is an acronym used with different meanings, each with its set of commands:
FTP protocol commands (e.g., USER, PASV, PORT etc)
FTP application commands, associated with a FTP client (e.g., get, put, dir
etc).
When using different Operating Systems one might find that the FTP application
works in different ways, even though they may be using the same FTP protocol.
The commands described below should work in most OS. However different FTP
clients may have incomplete implementations or use non­standard FTP
application commands.
To start the exercise:

  1. Open a terminal
  2. Issue the command:
    ftp servername
    Use any public FTP server you might know.
  3. The server will ask for a username and a password. As the FTP is a public
    one, there might be a guest user that general public can use (usually the word
    anonymous). The password could be anything. It is common practice to fill this
    field with your email address (this is not mandatory, but it is a contribution
    to the administrator’s log) anonymous
    [email protected] (or some random chars)
  4. When the connection is established, it is time to see what files the server
    has to offer. The command to list files and directories is:
    ls (dir might also work…)
  5. To change directories:
    cd
  6. To download a file:
    get
  7. To upload a file (many servers will not allow that!)
    put
  8. To download all the files with extension .txt:
    nget <*.txt>
  9. To see other commands (implementation dependent), type:
    help
    10)In order to choose between binary and ascii files one needs to issue
    either:
    bin
    asc

Part 2

We have seen some examples using the application called telnet to connect to
servers listening to certain ports (see some examples in Chapter 2). Does that
work with FTP?
Try downloading a file connecting via telnet:
telnet ftp.servername 21
Key questions:

  1. Can you connect?
  2. Can you download a file successfully? Why or why not?

Part 3

Understanding the difference between FTP “protocol commands” and “application
commands”:
We have looked at protocol commands, such as: RETR, USER, PASS, STOR etc.
Also, there are application commands with an FTP client: get, put, ls etc

Guidelines

The server needs to interpret requests that the client sends. To successfully
implement LIST, STOR and RETR, the server has also to interpret the following
protocol commands: USER, PASS, SYST, PASV, PORT, QUIT. Learn about the
protocol commands and response messages that need to be issued. Refer to the
material given in class, and find additional information about FTP at
http://www.freesoft.org/CIE/RFC/959/
.
Remember that the FTP protocol requires two connections, one in port 21 and a
data connection in port 20 (actually any other random port). The machines in
the lab may not allow users to bind applications to these ports.
Alternatively, use ports 1121 and 1120. You will need to start the ftp client
indicating that you want port 1121 to be used:
$ftp 127.0.0.1 1121 OR
$ftp
ftp> open 127.0.0.1 1121
The interpretation of the protocol commands can be coded as the following
example:
// USER
if (strncmp(rbuffer, “USER”, 4) == 0) {
printf(“Logging in \n”);
sprintf(sbuffer, “331 Password required (anything will do really… :­) \r\n”);
bytes = send(ns, sbuffer, strlen(sbuffer), 0);
}
// PASS
if (strncmp(rbuffer, “PASS”, 4) == 0) {
printf(“Typing password (anything will do… \n”);
sprintf(sbuffer, “230 Public logging in ok, type your email for password \r\n”);
bytes = send(ns, sbuffer, strlen(sbuffer), 0);
}
—|—
The assignment is going to be marked based on functionality. The server should
not crash if the user tries to issue commands that are not implemented. The
marks are distributed as follows:

  • 2 marks for correct connection/disconnection (the server should allow reconnection after errors, disconnections, etc) and LIST request (dir)
  • 3 marks for the RETR request
  • 3 marks for the STOR request
  • 2 marks for robustness (i.e., the server does not crash or lose the connection during my attempts to upload or download)

Notes:

  1. Your submission has to be a single source file (server) compatible with GCC (if using other compilers to develop the assignment, make sure the final source compiles on GCC). Submit to Stream.
  2. This assignment is worth 10 marks.
  3. You may lose marks for late assignments.

文章作者: SafePoker
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SafePoker !
  目录