tomshack
Junior Member level 3
the below is my homework about socket programming;can anyone help me about it ?please help me ...
The Problem:
"You can implement this program in any programming language."
Your task for this programming assignment is to create an application that
communicates across the Internet using sockets interface to the TCP/IP
protocol. You will create a simple File Transfer Protocol (FTP) client
application that connects to a remote computer and copies all the files
from a specified directory on the remote system to a specified directory
on the local system.
The FTP protocol specifies how an FTP client contacts an FTP server and
the control messages that are exchanged between the client and server. A
full implementation of FTP would allow the user to perform the following
tasks:
-login to the FTP server
-establish connections to transfer files
-download and upload files
To write this program you will first need to become familiar with the FTP
protocol. This protocol is completely specified in RFC 959. You only need
to implement the portions of the FTP protocol that are necessary to
download all the files in the directory specified by the user. The
sections of RFC 959 relevant to this assignment are specified below.
--------------------------------------------------------------------------------
The program shall be called sftp (Simplified FTP), and shall accept the
following command line arguments:
The name of the remote FTP server (e.g., ftp.gnu.org) or its IP address
(e.g., 199.232.41.7). This argument is required.
The directory on the remote FTP server from which you will transfer files
(the source directory). This argument is optional, and if not provided,
sftp should default to the login directory.
The directory on the local host to which you will transfer file (the
destination directory). This argument is optional, and if not provided,
sftp should default to the current working directory.
If only one directory name is provided, your program should assume it to
the the source directory on the remote server (the second argument).
Examples:
sftp ftp.gnu.org pub my_pub
transfers all of the files from the 'login directory'/pub directory at
ftp.gnu.org to a local directory called my_pub.
sftp ftp.gnu.org pub
transfers all of the files from the 'login directory'/pub directory at
ftp.gnu.org to the working directory on the local system.
sftp ftp.gnu.org
transfers all of the files from the login directory at ftp.gnu.org to the
working directory on the local system.
Your program must print nothing but a one-line status report at termination:
If the transfer is successful, the report should be: OK: XXX bytes copied,
specifying the total number of bytes copied, without leading zeros or
spaces
If an error occurs, the report should be: ERROR: followed by some
meaningful error message. If you received an error response across the FTP
control connection, you should use the complete ftp error response
message. Using just the ftp error code for that error is acceptable as
well. Refer to section 4.2 of RFC 959 for the various error codes.
For example:
OK: 12345 bytes copied
ERROR: 530 Login incorrect.
If your program terminates successfully, it should return a result of 0.
Otherwise, it should return a result of 1.
Your program should terminate on any unexpected response across the FTP
control connection, any network error across either connection, a file
write error, etc. In this case, you should issue an error message at
termination in the format specified above. Your program is not expected to
remove files from partially completed transfers.
The Problem:
"You can implement this program in any programming language."
Your task for this programming assignment is to create an application that
communicates across the Internet using sockets interface to the TCP/IP
protocol. You will create a simple File Transfer Protocol (FTP) client
application that connects to a remote computer and copies all the files
from a specified directory on the remote system to a specified directory
on the local system.
The FTP protocol specifies how an FTP client contacts an FTP server and
the control messages that are exchanged between the client and server. A
full implementation of FTP would allow the user to perform the following
tasks:
-login to the FTP server
-establish connections to transfer files
-download and upload files
To write this program you will first need to become familiar with the FTP
protocol. This protocol is completely specified in RFC 959. You only need
to implement the portions of the FTP protocol that are necessary to
download all the files in the directory specified by the user. The
sections of RFC 959 relevant to this assignment are specified below.
--------------------------------------------------------------------------------
The program shall be called sftp (Simplified FTP), and shall accept the
following command line arguments:
The name of the remote FTP server (e.g., ftp.gnu.org) or its IP address
(e.g., 199.232.41.7). This argument is required.
The directory on the remote FTP server from which you will transfer files
(the source directory). This argument is optional, and if not provided,
sftp should default to the login directory.
The directory on the local host to which you will transfer file (the
destination directory). This argument is optional, and if not provided,
sftp should default to the current working directory.
If only one directory name is provided, your program should assume it to
the the source directory on the remote server (the second argument).
Examples:
sftp ftp.gnu.org pub my_pub
transfers all of the files from the 'login directory'/pub directory at
ftp.gnu.org to a local directory called my_pub.
sftp ftp.gnu.org pub
transfers all of the files from the 'login directory'/pub directory at
ftp.gnu.org to the working directory on the local system.
sftp ftp.gnu.org
transfers all of the files from the login directory at ftp.gnu.org to the
working directory on the local system.
Your program must print nothing but a one-line status report at termination:
If the transfer is successful, the report should be: OK: XXX bytes copied,
specifying the total number of bytes copied, without leading zeros or
spaces
If an error occurs, the report should be: ERROR: followed by some
meaningful error message. If you received an error response across the FTP
control connection, you should use the complete ftp error response
message. Using just the ftp error code for that error is acceptable as
well. Refer to section 4.2 of RFC 959 for the various error codes.
For example:
OK: 12345 bytes copied
ERROR: 530 Login incorrect.
If your program terminates successfully, it should return a result of 0.
Otherwise, it should return a result of 1.
Your program should terminate on any unexpected response across the FTP
control connection, any network error across either connection, a file
write error, etc. In this case, you should issue an error message at
termination in the format specified above. Your program is not expected to
remove files from partially completed transfers.