else Just in case printfSomething went wrongn else if strcmppwd tempToken 0 pwd

Else just in case printfsomething went wrongn else if

This preview shows page 5 - 7 out of 7 pages.

} else // Just in case { printf("Something went wrong...\n"); } } else if (strcmp("pwd", tempToken) == 0) { // pwd command stuff here // Set opcode in tempChar tempChar = 'E'; // Send opcode write(socketID, &tempChar, sizeof(tempChar)); // Get back opcode response read(socketID, &tempChar, sizeof(tempChar)); // Get back length of pwd read(socketID, &int2bytes, sizeof(int2bytes)); // Get pwd read(socketID, tempString, (sizeof(char) * ntohs(int2bytes))); // Print out pwd printf("%s\n", tempString); } else if (strcmp("lcd", tempToken) == 0) {
Image of page 5
// lcd command stuff here tempToken = strtok(NULL, TOK_DELIM); check = chdir(tempToken); if (check == -1) // If dir change fails { if (errno == ENOENT) { printf("Directory does not " "exist\n"); } else if (errno == EACCES) { printf("Permission denied\n"); } else { printf("Unspecified error. " "Directory not " "changed\n"); } } } else if (strcmp("ldir", tempToken) == 0) { // ldir stuff here numFiles = scandir(".", &fileList, NULL, alphasort); if (numFiles == 0) { perror("myftp:scandir"); } else { for (i = 0; i < numFiles; ++i) { if (fileList[i]->d_type == DT_REG) { printf("f "); } else if (fileList[i]->d_type == DT_DIR) { printf("d "); } else { printf("o "); } printf("%s\n", fileList[i]->d_name); free(fileList[i]); } free(fileList); } } else if (strcmp("lpwd", tempToken) == 0) { // lpwd stuff here getcwd(tempString, 256); printf("%s\n", tempString); } else { // invalid command printf("Invalid command\n"); } } } while (1);
Image of page 6
}
Image of page 7

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture