Example #1
0
static int fetch_files(ssh_session session){
  int size;
  char buffer[16384];
  int mode;
  char *filename;
  int r;
  ssh_scp scp=ssh_scp_new(session, SSH_SCP_READ | SSH_SCP_RECURSIVE, "/tmp/libssh_tests/*");
  if(ssh_scp_init(scp) != SSH_OK){
	  fprintf(stderr,"error initializing scp: %s\n",ssh_get_error(session));
	  return -1;
  }
  printf("Trying to download 3 files (a,b,d) and 1 directory (c)\n");
  do {

	  r=ssh_scp_pull_request(scp);
	  switch(r){
	  case SSH_SCP_REQUEST_NEWFILE:
		  size=ssh_scp_request_get_size(scp);
		  filename=strdup(ssh_scp_request_get_filename(scp));
		  mode=ssh_scp_request_get_permissions(scp);
		  printf("downloading file %s, size %d, perms 0%o\n",filename,size,mode);
		  free(filename);
		  ssh_scp_accept_request(scp);
		  r=ssh_scp_read(scp,buffer,sizeof(buffer));
		  if(r==SSH_ERROR){
			  fprintf(stderr,"Error reading scp: %s\n",ssh_get_error(session));
			  return -1;
		  }
		  printf("done\n");
		  break;
	  case SSH_ERROR:
		  fprintf(stderr,"Error: %s\n",ssh_get_error(session));
		  return -1;
	  case SSH_SCP_REQUEST_WARNING:
		  fprintf(stderr,"Warning: %s\n",ssh_scp_request_get_warning(scp));
		  break;
	  case SSH_SCP_REQUEST_NEWDIR:
		  filename=strdup(ssh_scp_request_get_filename(scp));
		  mode=ssh_scp_request_get_permissions(scp);
		  printf("downloading directory %s, perms 0%o\n",filename,mode);
		  free(filename);
		  ssh_scp_accept_request(scp);
		  break;
	  case SSH_SCP_REQUEST_ENDDIR:
		  printf("End of directory\n");
		  break;
	  case SSH_SCP_REQUEST_EOF:
		  printf("End of requests\n");
		  goto end;
	  }
  } while (1);
  end:
  return 0;
}
Example #2
0
static int lscp_request_get_warning(lua_State *L){
	struct scp_ud * scpud = get_scpud(L);
	lua_pushstring(L,ssh_scp_request_get_warning(scpud->scp));
	return 1;
}