Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Experiment 7: An FTP Client

Lesson 7 of 11 in the free Network Programming Lab notes on Siksha Sarovar, written by Rohit Jangra.

Program Statement

Demonstrate FTP's two-connection architecture: a control connection on port 21 carrying commands/replies, plus a separate data connection negotiated via PASV.

/* mini_ftp.c — core fragment: control conn + PASV data conn */
send_cmd(ctrl, "USER anonymous\r\n");   read_reply(ctrl);   /* 331 */
send_cmd(ctrl, "PASS guest@\r\n");      read_reply(ctrl);   /* 230 */
send_cmd(ctrl, "PASV\r\n");
/* reply: 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)  */
sscanf(reply, "%*[^(](%d,%d,%d,%d,%d,%d)", &h1,&h2,&h3,&h4,&p1,&p2);
int port = p1 * 256 + p2;                 /* data port           */
int data = tcp_connect_ip(h1,h2,h3,h4, port);
send_cmd(ctrl, "LIST\r\n");              read_reply(ctrl);   /* 150 */
while ((n = read(data, buf, sizeof(buf))) > 0) write(1, buf, n);
close(data);                               read_reply(ctrl);   /* 226 */
send_cmd(ctrl, "QUIT\r\n");

Record Task

Draw the two-connection diagram; explain active vs passive mode and why NAT killed active mode (the server cannot connect in to a client behind NAT, so the client must open the data connection out — passive).

Theory Link

Unit 1 — one application, multiple simultaneous connections.