1 / 9

File Transfer

File Transfer. Transfer a file from one DTE to another DTE. Issues:. - Are file attributes (name, extension, ownership, time, size, etc.) transferred? - What will happen to the file on the destination DTE if the file transfer fails? Left or deleted?

hjames
Download Presentation

File Transfer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File Transfer • Transfer a file from one DTE to another DTE. • Issues: - Are file attributes (name, extension, ownership, time, size, etc.) transferred? - What will happen to the file on the destination DTE if the file transfer fails? Left or deleted? - Does ACK mean successful reception or successful writing to the disk on destination DTE?

  2. File System • File system is responsible for the generation of and access to files stored on some external medium, typically a disk. • Typical file system operations: • Files consist of a series of bytes often grouped into structures known as records. • Each file opened is associated with a handle, or file descriptor. - Creation - Opening - Closing - Reading: sequential or direct - Writing

  3. File Transfer Protocol Three basic operations: • File identification • End-of-file indication - Open existing file for reading on one DTE - Create new file on the other DTE - File name (and path, etc.) must be specified on both machines. - File attributes must be associated with the new file - file transfer can be aborted at this point for reasons like: - file to be copied does not exist - file name is already in use on the receiving DTE - the user does not have the necessary access right to the file - An end-of-file indication must be sent to the destination.

  4. File Transfer Protocol [cont’d] • Record Transfer - Source: 1. Open the file 2. Read a record 3. Pass the record to the communication software 4. Repeat steps 2 and 3 until end-of-file is detected - Destination: 1. Create the file 2. Wait for a record 3. Write the record to the newly created file 4. Repeat steps 2 and 3 until end-of-file is indicated - Need handshake between file transfer and comm. Software. - Many file transfer protocols also implement end-to-end ACK.

  5. Commkit File Transfer • s&wdisk.c: a simple file transfer utility using low-level stop-and-wait softwares&wlow.c. • Two modes: • Restrictions: - Source: read, transmit record one at a time - Destination: wait, receive, write - a maximum of 80 bytes per unit can be transferred - half-duplex communication

  6. s&wdisk( ) s&wdisk( ) 1 4 3a 2 s&wlow( ) s&wlow( ) 3b Implementation • s&wdisk.c: a simple file transfer utility using low-level stop-and-wait softwares&wlow.c. struct disk_msg { char option; /* Message option: EOF:1, MORE_TO_COME: 2 */ char data[REC_LEN]; /* Data to be sent with the option */ };

  7. Main void main(int argc, char *argv[]) { /* - mainline for stop-and-wait protocol example C:\> s&wdisk LineSpeed Port Protocol Filename - the Protocol is either X (xmit) or R (recv) -- the default is receive */ int line_speed; line_speed = get_line_speed(argv[1]); if (line_speed > 0) { initialize(line_speed, argv[2][0], argv[3][0]); if (stop_and_wait_init(argv[3][0])) read_and_send(argv[4]); else receive_and_write(argv[4]); rtn_to_dos(); } }

  8. void read_and_send (char *fname) // opens the specified file (name pointed to by `fname') fd = open(fname, O_RDONLY); while (running) { // up to REC_LEN bytes are read and passed to the handler for transmission if ((size = read(fd, message.data, REC_LEN)) == 0) message.option = EOF; else message.option = MORE_TO_COME; send(APPLICATION, handler_id, &message, size + 1); // the process then stops and waits for an acknowledgement from the remote process (via the handler); this continues until there are no further bytes in the file and the process signals end-of-file (EOF) do { recv(&src, APPLICATION, &ch, 1); if (src == KEYIH && ch == ETX) running = FALSE; } while (running && src != handler_id); /* Exit if ^C or SPxIH */ if (message.option == EOF) running = FALSE; } close(fd);

  9. void receive_and_write (char *fname) // opens a file for writing, file name is pointed to by `fname` fd = open(fname, O_WRONLY | O_CREAT, S_IREAD | S_IWRITE) //records are written to the file as they are received //end-of-file is signalled when the message option equals EOF do { size = recv(&src, APPLICATION, &message, sizeof(struct disk_msg)); if (message. option != EOF) write(fd, message. data, size - 1); } while (message . option != EOF); close(fd); /* CTRL-Z is NOT written to the file */

More Related