示例#1
0
int main(int argc, char *argv[]) {
    char buf[NET_BUF];
    int s, len, port;
    char *server_name;

    if(argc != 3) {
        printf("usage: ./myftp <server> <port>\n");
        return 0;
    }
    server_name = argv[1];
    port = atoi(argv[2]);

    s = get_client_socket(argv[1], port);    

    char line[BUF_SIZE];
    help();
    while(1) {
        printf("myftp>>> ");
        read_line(line);

        if (strcmp(line, "DWLD") == 0) {
            dwld(s);
        } else if (strcmp(line, "UPLD") == 0) {
            upld(s);
        } else if (strcmp(line, "LIST") == 0) {
            list(s);
        } else if (strcmp(line, "MDIR") == 0) {
            mdir(s);
        } else if (strcmp(line, "RDIR") == 0) {
            rdir(s);
        } else if (strcmp(line, "CDIR") == 0) {
            cdir(s);
        } else if (strcmp(line, "DELF") == 0) {
            delf(s);
        } else if (strcmp(line, "HELP") == 0) {
            help();
        } else if (strcmp(line, "QUIT") == 0) {
            printf("goodbye\n");
            quit(s);
            close(s);
            break;
        } else {
            printf("Unrecognized command: %s\n", line);
        }
        
    }
    return 0;
}
示例#2
0
文件: main.c 项目: fcote/eftp-client
int loop(int sock) {
    struct stat obj;
    size_t size;
    int success;
    char buf[128], filename[96], command[8], *response;

    int i = 1;
    while(1)
    {
        printf("%s\n","Enter a command (ls, cd, pwd, rm, downl, upld, rpwd, rls, rcd, quit): ");
        scanf("%s", command);

        if(!strcmp(command, "ls")) {
            if(ls()) {
                printf("%s\n","The remote directory listing is as follows: ");
                system("cat ls.txt");
                system("rm ls.txt");
            }
        } else if(!strcmp(command, "cd")) {
            printf("%s\n","Enter the path to change the directory: ");
            scanf("%s", filename);
            printf("%s\n", cd(filename) ? "Directory changed successfully !" : "Error when trying to change directory");
        }  else if(!strcmp(command, "pwd")) {
            if(pwd()) {
                printf("%s\n","The current directory name is: \n");
                system("cat pwd.txt");
                system("rm pwd.txt");
            }
        }  else if(!strcmp(command, "rm")) {
            printf("%s\n","Enter the filename to remove: ");
            scanf("%s", filename);
            printf("%s\n", rm(filename) ? "File removed successfully !" : "Error when trying to remove file");
        } else if(!strcmp(command, "downl")) {
            printf("%s\n","Enter filename to get: ");
            scanf("%s", filename);
            success = downl(sock, filename, buf, size, i);
            printf(success ? "File successfully downloaded\n" : "Failed to download the requested file\n");
        } else if(!strcmp(command, "upld")) {
            printf("%s\n","Enter filename to put to server: ");
            scanf("%s", filename);
            success = upld(sock, filename, buf, obj, size);
            printf("%s\n", success ? "File successfully uploaded\n" : "Failed to upload the given file\n");
        } else if(!strcmp(command, "rpwd")) {
            response = rpwd(sock, buf);
            printf("%s%s\n","The current remote directory name is: ", response);
        } else if(!strcmp(command, "rls")) {
            success = rls(sock, buf, size);
            if(success) {
                printf("%s\n","The remote directory listing is as follows:\n");
                system("cat temp.txt");
                system("rm temp.txt");
            }
        } else if(!strcmp(command, "rcd")) {
            printf("%s\n", "Enter the path to change the remote directory: ");
            scanf("%s", filename);
            success = rcd(sock, filename, buf);
            printf("%s\n", success ? "Directory changed successfully !" : "Error when trying to change directory");
        } else if(!strcmp(command, "quit")) {
            success = quit(sock, buf);
            if(success) {
                printf("%s\n", "Server closed\nQuitting..\n");
                return 0;
            }
            printf("%s\n", "Server failed to close the connection\n");
        } else {
            printf("%s\n", "Please choose a choice from the list.");
        }
    }
}