Computer Networks FTP Tips
Computer Networks FTP Tips
https://rtpnotes.vercel.app
https://pgmsite.netlify.app
Computer-Networks-FTP-Program-Tips
FTP-Client
Include Statements
FTP-Client: Basic Algorithm for remembering
Main function
getfunction
FTP-Client: Steps in more detail
Main function
1. Create the socket
2. Setup server address struct
3. Connect to the server
4. Loop
4.1 Read get or close
5. Close control socket and data socket
getfunction
1. Read filename and send filename to server
2. Receive validity check
3. Create data socket and setup struct
4. Connect to server and receive data
5. Write data to file
FTP-Server
FTP-Server: Basic Algorithm for remembering
Main function
sendfile function
FTP-Server: Steps in more detail
Main function
1. Create socket for control communication
2. Setup control socket address struct
3. Bind the control socket
4. Listen for incoming connections
5. Accept connection from client
6. Loop
6.1 Receive command from client
6.2 Open the requested file and send success message to client
6.3 Create socket for data transfer and setup data structure
6.4 Bind and listen for connections
6.5 Accept connection and execute sendfile function
6.6 Send file buffer to the client
6.7 Close the file, connection and data socket
7. Close the control socket and exit
sendfile function
FTP-Client
Include Statements
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/wait.h>
FTP-Client: Basic Algorithm for remembering
Main function
get_function
1. Enter filename
2. Send filename to the server
3. Receive validity check from server (Verifying whether the file exists or not)
4. Create data socket
5. Setup data connection address struct
6. Receive file data from server
7. Create a new file and write the file data
8. Close the file
9. Close the data socket
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = 2000;`
4. Loop
scanf("%s", command);
if (strcmp(command, "get") == 0) {
// Send 'get' command to the server
send(csd, command, sizeof(command), 0);
get_function(csd, data, argv[1]);
} else if (strcmp(command, "close") == 0) {
// Send 'close' command to the server and break the loop
send(csd, command, sizeof(command), 0);
break;
} else {
printf("Invalid command\n");
}
close(csd);
close(dd);
get_function
data.sin_family = AF_INET;
data.sin_addr.s_addr = inet_addr(data_addr);
data.sin_port = htons(8080);
FTP-Server
FTP-Server: Basic Algorithm for remembering
Main function
control.sin_family = AF_INET;
control.sin_port = htons(port);
control.sin_addr.s_addr = INADDR_ANY;
listen(lfd, 5);
6.2 Open the requested file and send success message to client
fp = fopen(rBuf, "r");
send(confd, "success", sizeof("success"), 0);
6.3 Create socket for data transfer and setup data structure
data.sin_family = AF_INET;
data.sin_addr.s_addr = INADDR_ANY;
data.sin_port = htons(8080)
n = sizeof(data_client);
confd2 = accept(fd, (struct sockaddr *)&data_client, &n);
send_file(fp);
fclose(fp);
close(confd2);
close(fd);
close(confd);
close(lfd);
send_file function