Question

*****Can someone please HELP me with this assignment please, I am struggling with this assignment and...

*****Can someone please HELP me with this assignment please, I am struggling with this assignment and would appreciate some help, needs to be done in c/c++ *******

  1. (100 marks) In this problem, you will write a file transfer program for transferring files between two computers connected by a network. The protocol that you will implement is called the Simple File Transfer Protocol (SFTP). The complete description for SFTP is given below.

PART 1

SFTP is a simple protocol for transferring small files from the file system on one computer to the file system on another. The computers are connected by a network. Within the context of SFTP, a small file is defined as one containing up to ten lines of text-based data consisting of uppercase and lowercase letters, the digits 0 through 9, and typical punctuation.

Any transfer begins with a request from a client to read (write) a file from (to) the file system on the server.

In a read request, the server acknowledges the request by sending the requested file to be written on the client’s file system. Upon completion of the transfer, the server sends an end-of-file message to the client, causing the client to terminate the connection.

In a write request, the server acknowledges the request by sending an acknowledgement. The client responds by sending the file to be written on the server’s file system. Upon completion of the transfer, the client sends an end-of-file message to the server and then terminates the connection.

PART 2

A transfer is initiated by a client sending a read request (rrq) or write request (wrq) message to the server.

Read request: Upon receiving an rrq message, the server will determine whether the file is empty. If the file is empty, the server will respond by sending an end-of-file (eof) message to the client. Upon receipt of the eofmessage, the client will respond by terminating the connection with the server. If the file is not empty, the server will respond by sending to the client a data (data) message containing the first line of the requested file. Upon receipt of the data message, the client will respond by sending an acknowledgement (ack) message to the server. Upon receipt of the ack message, the server will respond by sending the next line of the requested file. data and ackmessages will be exchanged in this way until all data in the file has been transferred. When there is no more data to transfer, the server will respond by sending an eof message to the client. Upon receipt of the eof message, the client will respond by terminating the connection with the server. If the server discovers that the number of lines in the file being read exceeds ten, the server will respond by sending a file size exceeded (fse) message to the client. Upon receipt of the fse message, the client will respond by sending either a continue (cont) message or an abort (abort) message to the server. Upon receipt of a cont message, the server will continue to transfer data to completion in the normal way. Upon receipt of an abort message, the server will send an ack message to the client. Upon receipt of the ack message, the client will respond by deleting all data received from the server and terminating the connection with the server.

Write request: Upon receiving a wrq message, the server will respond by sending to the client an acknowledgement(ack) message. Upon receipt of the ack message, the client will determine whether the file is empty. If the file is empty, the client will respond by sending an end-of-file (eof) message to the server. Upon receipt of the eofmessage, the server will respond by sending an ack message to the client. Upon receipt of the ack message, the client will respond by terminating the connection with the server. If the file is not empty, the client will respond by sending a data (data) message containing the first line of the file. Upon receipt of the data message, the server will respond by sending an ack message to the client. Upon receipt of the ack message, the client will respond by sending the next line of the file. data and ack messages will be exchanged in this way until all data in the file has been transferred. When there is no more data to transfer, the client will respond by sending an eof message to the server. Upon receipt of the eof message, the server will respond by sending an ack message to the client. Upon receipt of the ack message, the client will respond by terminating the connection with the server. If the server discovers that the number of lines in the file being written exceeds ten, the server will respond by sending a file size exceeded (fse) message to the client. Upon receipt of the fse message, the client will respond by sending an abort (abort) message to the server. Upon receipt of the abort message, the server will respond by sending an ackmessage to the client and deleting all data received from the client. Upon receipt of the ack message, the client will respond by terminating the connection with the server.

PART 3

Implement client and server programs for the SFTP protocol described above. The client and server programs should communicate via TCP using Berkeley sockets. The client and server programs must be based upon the source code provided in socketClient.c, socketServer.c, socketFunctions.h, and socketInclude.h. These files can be found in the directory /home/venus/hilder/cs330/assignment5/datafiles. Instructions for compiling and running these programs can be found at the end of the Programming Sockets section of the Course Notes.

Feel free to change the source code in any way you want, but you might want to consider first studying the source code, compiling it, running it, and stepping through the code with the debugger to get a better understanding as to how it works (particularly the sending and receiving of messages).

Note: When testing your client and server, run them from different machines and different directories. Also, be sure to kill all server processes you have running before you log off.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SERVER PROGRAM:


#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#define IP_PROTOCOL 0
#define PORT_NO 15050
#define NET_BUF_SIZE 10
#define cipherKey 'S'
#define sendrecvflag 0
#define nofile "File Not Found!"

// function to clear buffer
void clearBuf(char* b)
{
   int i;
   for (i = 0; i < NET_BUF_SIZE; i++)
       b[i] = '\0';
}

// function to encrypt
char Cipher(char ch)
{
   return ch ^ cipherKey;
}

// function sending file
int sendFile(FILE* fp, char* buf, int s)
{
   int i, len;
   if (fp == NULL) {
       strcpy(buf, nofile);
       len = strlen(nofile);
       buf[len] = EOF;
       for (i = 0; i <= len; i++)
           buf[i] = Cipher(buf[i]);
       return 1;
   }

   char ch, ch2;
   for (i = 0; i < s; i++) {
       ch = fgetc(fp);
       ch2 = Cipher(ch);
       buf[i] = ch2;
       if (ch == EOF)
           return 1;
   }
   return 0;
}

// driver code
int main()
{
   int sockfd, nBytes;
   struct sockaddr_in addr_con;
   int addrlen = sizeof(addr_con);
   addr_con.sin_family = AF_INET;
   addr_con.sin_port = htons(PORT_NO);
   addr_con.sin_addr.s_addr = INADDR_ANY;
   char net_buf[NET_BUF_SIZE];
   FILE* fp;

   // socket()
   sockfd = socket(AF_INET, SOCK_DGRAM, IP_PROTOCOL);

   if (sockfd < 0)
       printf("\nfile descriptor not received!!\n");
   else
       printf("\nfile descriptor %d received\n", sockfd);

   // bind()
   if (bind(sockfd, (struct sockaddr*)&addr_con, sizeof(addr_con)) == 0)
       printf("\nSuccessfully binded!\n");
   else
       printf("\nBinding Failed!\n");

   while (1) {
       printf("\nWaiting for file name...\n");

       // receive file name
       clearBuf(net_buf);

       nBytes = recvfrom(sockfd, net_buf,
                       NET_BUF_SIZE, sendrecvflag,
                       (struct sockaddr*)&addr_con, &addrlen);

       fp = fopen(net_buf, "r");
       printf("\nFile Name Received: %s\n", net_buf);
       if (fp == NULL)
           printf("\nFile open failed!\n");
       else
           printf("\nFile Successfully opened!\n");

       while (1) {

           // process
           if (sendFile(fp, net_buf, NET_BUF_SIZE)) {
               sendto(sockfd, net_buf, NET_BUF_SIZE,
                   sendrecvflag,
                   (struct sockaddr*)&addr_con, addrlen);
               break;
           }

           // send
           sendto(sockfd, net_buf, NET_BUF_SIZE,
               sendrecvflag,
               (struct sockaddr*)&addr_con, addrlen);
           clearBuf(net_buf);
       }
       if (fp != NULL)
           fclose(fp);
   }
   return 0;
}

CLIENT PROGRAM:

// client code for UDP socket programming
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#define IP_PROTOCOL 0
#define IP_ADDRESS "127.0.0.1" // localhost
#define PORT_NO 15050
#define NET_BUF_SIZE 32
#define cipherKey 'S'
#define sendrecvflag 0

// function to clear buffer
void clearBuf(char* b)
{
   int i;
   for (i = 0; i < NET_BUF_SIZE; i++)
       b[i] = '\0';
}

// function for decryption
char Cipher(char ch)
{
   return ch ^ cipherKey;
}

// function to receive file
int recvFile(char* buf, int s)
{
   int i;
   char ch;
   for (i = 0; i < s; i++) {
       ch = buf[i];
       ch = Cipher(ch);
       if (ch == EOF)
           return 1;
       else
           printf("%c", ch);
   }
   return 0;
}

// driver code
int main()
{
   int sockfd, nBytes;
   struct sockaddr_in addr_con;
   int addrlen = sizeof(addr_con);
   addr_con.sin_family = AF_INET;
   addr_con.sin_port = htons(PORT_NO);
   addr_con.sin_addr.s_addr = inet_addr(IP_ADDRESS);
   char net_buf[NET_BUF_SIZE];
   FILE* fp;

   // socket()
   sockfd = socket(AF_INET, SOCK_DGRAM,
                   IP_PROTOCOL);

   if (sockfd < 0)
       printf("\nfile descriptor not received!!\n");
   else
       printf("\nfile descriptor %d received\n", sockfd);

   while (1) {
       printf("\nPlease enter file name to receive:\n");
       scanf("%s", net_buf);
       sendto(sockfd, net_buf, NET_BUF_SIZE,
           sendrecvflag, (struct sockaddr*)&addr_con,
           addrlen);

       printf("\n---------Data Received---------\n");

       while (1) {
           // receive
           clearBuf(net_buf);
           nBytes = recvfrom(sockfd, net_buf, NET_BUF_SIZE,
                           sendrecvflag, (struct sockaddr*)&addr_con,
                           &addrlen);

           // process
           if (recvFile(net_buf, NET_BUF_SIZE)) {
               break;
           }
       }
       printf("\n-------------------------------\n");
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
*****Can someone please HELP me with this assignment please, I am struggling with this assignment and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Project Description In this project, you will be developing a multithreaded Web server and a simple...

    Project Description In this project, you will be developing a multithreaded Web server and a simple web client. The Web server and Web client communicate using a text-based protocol called HTTP (Hypertext Transfer Protocol). Requirements for the Web server The server is able to handle multiple requests concurrently. This means the implementation is multithreaded. In the main thread, the server listens to a specified port, e.g., 8080. Upon receiving an HTTP request, the server sets up a TCP connection to...

  • Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will...

    Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will write a client and server program that enables the client to determine the round-trip time (RTT) to the server. To determine the RTT delay, the client records the time on sending a ping request to the server, and then records the time on receiving a ping response from the server. The difference in the two times is the RTT. The ping message contains 2...

  • I am really struggling with this assignment, can anyone help? It is supposed to work with...

    I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...

  • Can someone help me with this assignment. I am struggling with the formatting PART A Create...

    Can someone help me with this assignment. I am struggling with the formatting PART A Create a web page containing data of your choice and the following styles: A background image that repeats vertically on the right hand side of the page. The image should not scroll with the page contents. All the headings should be displayed in green and Arial fonts. Create at least three headings in your web page. A paragraph style with centered double-spaced text that displays...

  • Can someone please help me with this problem, I am new in this and I got no idea how to make it ?

    Must contain several methods to provide reading functions,performing calculations and posting the results.Main Main method for executing execution Method for reading data from the keyboard Method for performing calculations according to the problem request Method for posting resultsThe main method must contain at least:A menu for selecting the function (Reading data, Performing calculations, Posting ioutput, Exit the program) using the switch / case instruction.The menu must be included within a do / while cycle in order for the e functions...

  • I am really struggling with quantum. Can someone please help me with those questions 4.2. Using...

    I am really struggling with quantum. Can someone please help me with those questions 4.2. Using basic quantum concepts Pr 4.3 This problem reinforces your understanding of normalization, prob- ability densities, and mean (expectation) values. The ground state wave function for a particle in a wire is = (2/a)/2 sin(x/a). (a) Define the ground state wave function for the particle in a wire using Maple. Hint: see Appendix A. (b) Write down a mathematical expression for the normalization of the...

  • This is in C. For this assignment we will write a simple database server. We will...

    This is in C. For this assignment we will write a simple database server. We will be creating a simple database of student records, so let’s describe these first. The format of a student record is as follows: typedef struct student {     char lname[ 10 ], initial, fname[ 10 ];     unsigned long SID;     float GPA; } SREC; Part One – the Server We will create a database server. The job of the server is to accept a...

  • HI, I am having trouble finsihing this program i was wondering if someone could help me....

    HI, I am having trouble finsihing this program i was wondering if someone could help me. Thanks in adavnce. Here is the code that I have so far..... //Stack.h // implementation file for the stack class #include <iostream> using namespace std; const int stack_size = 100; class stack { private: char data [stack_size]; // elements in the stack int top; // index of the top element of the stack public: stack (); // constructor creates an empty stack void push...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

  • please help!!!! JAVA I done the project expect one part but I still give you all...

    please help!!!! JAVA I done the project expect one part but I still give you all the detail that you needed... and I will post my code please help me fix the CreateGrid() part in main and make GUI works    List Type Data Structures Overview : You will be implementing my version of a linked list. This is a linked list which has possible sublists descending from each node. These sublists are used to group together all nodes which...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT