📄 client.c
字号:
strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_mtime)); d_printf("Modify: %s\n", mode_str); strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_ctime)); d_printf("Change: %s\n", mode_str); return 0;}/**************************************************************************** UNIX chown.****************************************************************************/static int cmd_chown(void){ pstring src; uid_t uid; gid_t gid; pstring buf, buf2, buf3; struct cli_state *targetcli; pstring targetname; pstrcpy(src,cur_dir); if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) || !next_token_nr(NULL,buf2,NULL, sizeof(buf2)) || !next_token_nr(NULL,buf3,NULL, sizeof(buf3))) { d_printf("chown uid gid file\n"); return 1; } uid = (uid_t)atoi(buf); gid = (gid_t)atoi(buf2); pstrcat(src,buf3); if ( !cli_resolve_path( "", cli, src, &targetcli, targetname ) ) { d_printf("chown %s: %s\n", src, cli_errstr(cli)); return 1; } if (!SERVER_HAS_UNIX_CIFS(targetcli)) { d_printf("Server doesn't support UNIX CIFS calls.\n"); return 1; } if (!cli_unix_chown(targetcli, targetname, uid, gid)) { d_printf("%s chown file %s uid=%d, gid=%d\n", cli_errstr(targetcli), src, (int)uid, (int)gid); return 1; } return 0;}/**************************************************************************** Rename some file.****************************************************************************/static int cmd_rename(void){ pstring src,dest; pstring buf,buf2; pstrcpy(src,cur_dir); pstrcpy(dest,cur_dir); if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) || !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) { d_printf("rename <src> <dest>\n"); return 1; } pstrcat(src,buf); pstrcat(dest,buf2); if (!cli_rename(cli, src, dest)) { d_printf("%s renaming files\n",cli_errstr(cli)); return 1; } return 0;}/**************************************************************************** Print the volume name.****************************************************************************/static int cmd_volume(void){ fstring volname; uint32 serial_num; time_t create_date; if (!cli_get_fs_volume_info(cli, volname, &serial_num, &create_date)) { d_printf("Errr %s getting volume info\n",cli_errstr(cli)); return 1; } d_printf("Volume: |%s| serial number 0x%x\n", volname, (unsigned int)serial_num); return 0;}/**************************************************************************** Hard link files using the NT call.****************************************************************************/static int cmd_hardlink(void){ pstring src,dest; pstring buf,buf2; struct cli_state *targetcli; pstring targetname; pstrcpy(src,cur_dir); pstrcpy(dest,cur_dir); if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) || !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) { d_printf("hardlink <src> <dest>\n"); return 1; } pstrcat(src,buf); pstrcat(dest,buf2); if ( !cli_resolve_path( "", cli, src, &targetcli, targetname ) ) { d_printf("hardlink %s: %s\n", src, cli_errstr(cli)); return 1; } if (!SERVER_HAS_UNIX_CIFS(targetcli)) { d_printf("Server doesn't support UNIX CIFS calls.\n"); return 1; } if (!cli_nt_hardlink(targetcli, targetname, dest)) { d_printf("%s doing an NT hard link of files\n",cli_errstr(targetcli)); return 1; } return 0;}/**************************************************************************** Toggle the prompt flag.****************************************************************************/static int cmd_prompt(void){ prompt = !prompt; DEBUG(2,("prompting is now %s\n",prompt?"on":"off")); return 1;}/**************************************************************************** Set the newer than time.****************************************************************************/static int cmd_newer(void){ pstring buf; BOOL ok; SMB_STRUCT_STAT sbuf; ok = next_token_nr(NULL,buf,NULL,sizeof(buf)); if (ok && (sys_stat(buf,&sbuf) == 0)) { newer_than = sbuf.st_mtime; DEBUG(1,("Getting files newer than %s", asctime(localtime(&newer_than)))); } else { newer_than = 0; } if (ok && newer_than == 0) { d_printf("Error setting newer-than time\n"); return 1; } return 0;}/**************************************************************************** Set the archive level.****************************************************************************/static int cmd_archive(void){ pstring buf; if (next_token_nr(NULL,buf,NULL,sizeof(buf))) { archive_level = atoi(buf); } else d_printf("Archive level is %d\n",archive_level); return 0;}/**************************************************************************** Toggle the lowercaseflag.****************************************************************************/static int cmd_lowercase(void){ lowercase = !lowercase; DEBUG(2,("filename lowercasing is now %s\n",lowercase?"on":"off")); return 0;}/**************************************************************************** Toggle the case sensitive flag.****************************************************************************/static int cmd_setcase(void){ BOOL orig_case_sensitive = cli_set_case_sensitive(cli, False); cli_set_case_sensitive(cli, !orig_case_sensitive); DEBUG(2,("filename case sensitivity is now %s\n",!orig_case_sensitive ? "on":"off")); return 0;}/**************************************************************************** Toggle the recurse flag.****************************************************************************/static int cmd_recurse(void){ recurse = !recurse; DEBUG(2,("directory recursion is now %s\n",recurse?"on":"off")); return 0;}/**************************************************************************** Toggle the translate flag.****************************************************************************/static int cmd_translate(void){ translation = !translation; DEBUG(2,("CR/LF<->LF and print text translation now %s\n", translation?"on":"off")); return 0;}/**************************************************************************** Do the lcd command. ****************************************************************************/static int cmd_lcd(void){ pstring buf; pstring d; if (next_token_nr(NULL,buf,NULL,sizeof(buf))) chdir(buf); DEBUG(2,("the local directory is now %s\n",sys_getwd(d))); return 0;}/**************************************************************************** Get a file restarting at end of local file. ****************************************************************************/static int cmd_reget(void){ pstring local_name; pstring remote_name; char *p; pstrcpy(remote_name, cur_dir); pstrcat(remote_name, "\\"); p = remote_name + strlen(remote_name); if (!next_token_nr(NULL, p, NULL, sizeof(remote_name) - strlen(remote_name))) { d_printf("reget <filename>\n"); return 1; } pstrcpy(local_name, p); dos_clean_name(remote_name); next_token_nr(NULL, local_name, NULL, sizeof(local_name)); return do_get(remote_name, local_name, True);}/**************************************************************************** Put a file restarting at end of local file. ****************************************************************************/static int cmd_reput(void){ pstring local_name; pstring remote_name; pstring buf; char *p = buf; SMB_STRUCT_STAT st; pstrcpy(remote_name, cur_dir); pstrcat(remote_name, "\\"); if (!next_token_nr(NULL, p, NULL, sizeof(buf))) { d_printf("reput <filename>\n"); return 1; } pstrcpy(local_name, p); if (!file_exist(local_name, &st)) { d_printf("%s does not exist\n", local_name); return 1; } if (next_token_nr(NULL, p, NULL, sizeof(buf))) pstrcat(remote_name, p); else pstrcat(remote_name, local_name); dos_clean_name(remote_name); return do_put(remote_name, local_name, True);}/**************************************************************************** List a share name. ****************************************************************************/static void browse_fn(const char *name, uint32 m, const char *comment, void *state){ fstring typestr; *typestr=0; switch (m) { case STYPE_DISKTREE: fstrcpy(typestr,"Disk"); break; case STYPE_PRINTQ: fstrcpy(typestr,"Printer"); break; case STYPE_DEVICE: fstrcpy(typestr,"Device"); break; case STYPE_IPC: fstrcpy(typestr,"IPC"); break; } /* FIXME: If the remote machine returns non-ascii characters in any of these fields, they can corrupt the output. We should remove them. */ if (!grepable) { d_printf("\t%-15s %-10.10s%s\n", name,typestr,comment); } else { d_printf ("%s|%s|%s\n",typestr,name,comment); }}/**************************************************************************** Try and browse available connections on a host.****************************************************************************/static BOOL browse_host(BOOL sort){ int ret; if (!grepable) { d_printf("\n\tSharename Type Comment\n"); d_printf("\t--------- ---- -------\n"); } if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1) d_printf("Error returning browse list: %s\n", cli_errstr(cli)); return (ret != -1);}/**************************************************************************** List a server name.****************************************************************************/static void server_fn(const char *name, uint32 m, const char *comment, void *state){ if (!grepable){ d_printf("\t%-16s %s\n", name, comment); } else { d_printf("%s|%s|%s\n",(char *)state, name, comment); }}/**************************************************************************** Try and browse available connections on a host.****************************************************************************/static BOOL list_servers(const char *wk_grp){ fstring state; if (!cli->server_domain) return False; if (!grepable) { d_printf("\n\tServer Comment\n"); d_printf("\t--------- -------\n"); }; fstrcpy( state, "Server" ); cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL, server_fn, state); if (!grepable) { d_printf("\n\tWorkgroup Master\n"); d_printf("\t--------- -------\n"); }; fstrcpy( state, "Workgroup" ); cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM, server_fn, state); return True;}/**************************************************************************** Print or set current VUID****************************************************************************/static int cmd_vuid(void){ fstring buf; if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { d_printf("Current VUID is %d\n", cli->vuid); return 0; } cli->vuid = atoi(buf); return 0;}/**************************************************************************** Setup a new VUID, by issuing a session setup****************************************************************************/static int cmd_logon(void){ pstring l_username, l_password; pstring buf,buf2; if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { d_printf("logon <username> [<password>]\n"); return 0; } pstrcpy(l_username, buf); if (!next_token_nr(NULL,buf2,NULL,sizeof(buf))) { char *pass = getpass("Password: "); if (pass) pstrcpy(l_password, pass); } else pstrcpy(l_password, buf2); if (!cli_session_setup(cli, l_username, l_password, strlen(l_password), l_password, strlen(l_password), lp_workgroup())) { d_printf("session setup failed: %s\n", cli_errstr(cli)); return -1; } d_printf("Current VUID is %d\n", cli->vuid); return 0;}/**************************************************************************** list active connections****************************************************************************/static int cmd_list_connect(void){ cli_cm_display(); return 0;}/**************************************************************************** display the current active client connection****************************************************************************/static int cmd_show_connect( void ){ struct cli_state *targetcli; pstring targetpath; if ( !cli_resolve_path( "", cli, cur_dir, &targetcli, targetpath ) ) { d_printf("showconnect %s: %s\n", cur_dir, cli_errstr(cli)); return 1; } d_printf("//%s/%s\n", targetcli->desthost, targetcli->share); return 0;}/* Some constants for completing filename arguments */#define COMPL_NONE 0 /* No completions */#define COMPL_REMOTE 1 /* Complete remote filename */#define COMPL_LOCAL 2 /* Complete local filename *//* This defines the commands supported by this client. * NOTE: The "!" must be the last one in the list because it's fn pointer * field is NULL, and NULL in that field is used in process_tok() * (below) to indicate the end of the list. crh */static struct{ const char *name; int (*fn)(void); const char *description; char compl_args[2]; /* Completion argument info */} commands[] = { {"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}}, {"altname",cmd_altname,"<file> show alt name",{COMPL_NONE,COMPL_NONE}}, {"archive",cmd_archive,"<level>\n0=ignore archive bit\n1=only get archive files\n2=only get archive files and reset archive bit\n3=get all files and reset archive bit",{COMPL_NONE,COMPL_NONE}}, {"blocksize",cmd_block,"blocksize <number> (default 20)",{COMPL_NONE,COMPL_NONE}}, {"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}}, {"case_sensitive",cmd_setcase,"toggle the case sensitive flag to server",{COMPL_NONE,COMPL_NONE}}, {"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}}, {"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_REMOTE}}, {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_REMOTE}}, {"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}}, {"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}}, {"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -