📝 FTP commands and responses list (12 MCQs)
FTP Command–Reply Interaction
FTP commands let a client control a file-transfer session through a text-based exchange with the server. Each command is interpreted by the server's protocol interpreter and produces at least one reply. Replies begin with a three-digit code followed by explanatory text, allowing software to determine success, continuation or failure without relying on wording alone. This design separates session control from the potentially lengthy movement of file contents.
Authentication, Navigation and Transfer Commands
USER and PASS provide account details; PWD reports the current directory; CWD changes directories; TYPE selects a representation mode; LIST requests a directory listing; RETR retrieves a file; and STOR stores one. QUIT ends the control session. PORT and PASV arrange data connection parameters rather than directly transferring file contents.
Three-Digit Reply Codes and Session Progress
The server sends a numeric reply after processing each command. Codes beginning with 1 indicate preliminary action, 2 indicate successful completion, 3 indicate that more information is needed, 4 indicate a transient negative response, and 5 indicate a permanent negative response. The exact three-digit code narrows the meaning within its class.
A Directory Listing Command Sequence
A client may send PWD and receive 257, then send CWD reports and receive 250 when the directory change succeeds. It can issue PASV, parse the server's endpoint reply, open the data connection and send LIST. A 150 reply indicates preliminary transfer action; a later 226 reports successful completion. The sequence demonstrates why a successful command and completed data transfer are separate events.
Command Groups and FTP State Changes
FTP commands define session operations, while replies describe server processing states. Some command groups have dependencies: RNFR identifies a file to rename and RNTO supplies the new name. A transfer command may produce preliminary and final replies because connection setup and data transmission are separate stages of one operation. This separation supports repeated operations within one authenticated control session.
Misconceptions About FTP Reply Codes
'Every 2xx code means a file was downloaded' is false because 2xx covers many successful command outcomes. 'The text after a reply code is standardized exactly' is incorrect because explanatory text may vary. 'A 150 reply proves transfer completion' is wrong because it is preliminary; a final reply such as 226 normally follows a completed transfer.
Interpreting Common FTP Commands and Replies
Memorize commands by function rather than as an isolated list: authentication, directory control, data setup, transfer and session termination. Distinguish 150 from 226, and understand the broad 1xx–5xx reply classes. Given a command transcript, identify the state reached and whether a data connection or further command is still required.
FTP Command and Reply Terms
- USER - Supplies the account name used for login.
- PASS - Supplies the account password.
- CWD - Changes the working directory.
- RETR - Requests a file from the server.
- 150 - Signals preliminary transfer action.
- 226 - Confirms successful data transfer completion.
📝 All FTP commands and responses list MCQs
Q1. If a client attempts to initiate a TCP connection before the server program has called listen(), what is the most likely outcome?
📖 Explanation: When the server has not called listen(), there is no socket bound to the destination port, so the TCP three‑way handshake cannot be completed. The client’s connect() call fails and returns an error such as ECONNREFUSED, indicating that the remote side actively refused the connection.
Q2. Which statement best compares the socket API with the Transport Layer Interface (TLI) regarding portability and usage?
📖 Explanation: The socket API originated on BSD Unix and was quickly adopted across many operating systems, making it highly portable and the de‑facto standard for network programming. TLI, while standardized, saw limited implementation and is less commonly used, so sockets are generally considered more portable and widely supported.
Q3. In the TCP/IP stack, the socket API primarily abstracts which layer for the application programmer?
📖 Explanation: The socket interface presents functions such as socket(), bind(), listen(), and send()/recv() that operate on transport‑layer protocols like TCP and UDP. It hides lower‑level details of IP routing and framing, allowing applications to work directly with reliable streams or datagrams without dealing with network‑layer or link‑layer specifics.
Q4. A server process crashes and restarts without re‑binding its listening socket. What problem is most likely to occur when a client later connects?
📖 Explanation: When the server restarts without rebinding, the operating system still holds the previous socket binding. Attempting to bind the same address and port results in an EADDRINUSE error, preventing the server from listening for new connections until the old socket is released or the address is cleared.
Q5. Why is the client’s lifetime typically finite while the server’s lifetime is considered infinite in a client‑server model?
📖 Explanation: A client initiates a request, processes the response, and then exits, giving it a bounded execution period. In contrast, a server must stay active to accept successive requests from many clients over time, so it is designed to run continuously, often until the system is shut down.
Q6. Which sequence of socket API calls must a server perform to accept a connection from a client that has called connect()?
📖 Explanation: The typical server setup is: create a socket with socket(), assign a local address with bind(), mark it as passive with listen(), and finally block awaiting a client using accept(). Only this order correctly prepares the socket to receive incoming connection requests.
Q7. If a server processes each client request sequentially in a single‑threaded loop, what is the most likely effect when several clients connect at the same time?
📖 Explanation: A single‑threaded server handles one request at a time; while it processes the first client, subsequent clients must wait. This queueing introduces additional waiting time, so later clients experience higher latency, even though no connections are refused unless resources are exhausted.
Q8. Between a multi‑threaded server that creates a thread per client and an event‑driven server using non‑blocking I/O, which design generally scales better under high concurrency and why?
📖 Explanation: Event‑driven architectures keep a small number of threads that multiplex many connections via non‑blocking I/O and readiness notifications. This eliminates the cost of creating, scheduling, and context‑switching thousands of threads, allowing the server to handle far more concurrent connections with lower memory and CPU overhead.
Q9. To guarantee that a client detects server unavailability within 2 seconds, which combination of TCP keepalive and application‑level heartbeat settings is most appropriate?
📖 Explanation: Setting TCP keepalive to trigger after 1 second, probing every 0.5 seconds with two attempts ensures the kernel detects a dead peer within roughly 2 seconds. Complementing this with an application‑level heartbeat sent every 1 second provides an additional safety net, guaranteeing detection well before the 2‑second deadline.
Q10. A client sends a request but receives no response before its timeout expires. Which recovery action is most appropriate according to reliable communication principles?
📖 Explanation: The standard approach is to verify that the TCP connection remains established and then retransmit the request. TCP will handle any required retransmissions at the transport level, but an explicit application‑level retry ensures the request is not lost while preserving the session.
Q11. What does the term “socket” denote in TCP/IP programming?
📖 Explanation: A socket is a software abstraction that represents one endpoint of a network communication channel. It is uniquely identified by the combination of an IP address and a port number, allowing processes to send and receive data over TCP or UDP without dealing directly with lower‑level protocol details.
Q12. If a server calls close() on a socket while there is still unsent data in the send buffer, what is the most likely consequence?
📖 Explanation: Calling close() initiates an active close, which may abort transmission of any data still queued in the send buffer. To guarantee that all pending data is transmitted before the connection is closed, the application should first invoke shutdown() with the appropriate flag (e.g., SHUT_WR) and then close() once the peer acknowledges receipt.