Esempio n. 1
0
int main()
{
    ssh_session my_ssh_session;
    int rc;
    int port = 22;

    my_ssh_session = ssh_new();
    if(my_ssh_session == NULL)
        exit(-1);
    ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
    ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
    ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "root");

    rc = ssh_connect(my_ssh_session);
    if(rc != SSH_OK)
    {
        fprintf(stderr, "Error connecting to localhost: %s\n", ssh_get_error(my_ssh_session));
        exit(-1);
    }
    
    scp_write(my_ssh_session);

    ssh_disconnect(my_ssh_session);
    ssh_free(my_ssh_session);
}
Esempio n. 2
0
File: ascp.c Progetto: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ascp1 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int         i,
               fd,
               loops,
               rest;
   char        block[1024];
   struct stat stat_buf;

   if (argc != 2)
   {
      (void)fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
      exit(-1);
   }
   if (scp_connect("localhost", 22, NULL, NULL, ".") == -1)
   {
      (void)fprintf(stderr, "scp_connect() failed\n");
      exit(-1);
   }
   if ((fd = open(argv[1], O_RDONLY)) == -1)
   {
      (void)fprintf(stderr, "Failed to open() %s : %s\n",
                    argv[1], strerror(errno));
      exit(-1);
   }
   if (fstat(fd, &stat_buf) == -1)
   {
      (void)fprintf(stderr, "Failed to fstat() %s : %s\n",
                    argv[1], strerror(errno));
      exit(-1);
   }
   if (scp_open_file(argv[1], stat_buf.st_size, stat_buf.st_mode) == -1)
   {
      (void)fprintf(stderr, "scp_open_file() %s failed\n", argv[1]);
      exit(-1);
   }
   loops = stat_buf.st_size / 1024;
   rest = stat_buf.st_size % 1024;
   fprintf(stdout, "\n");
   for (i = 0; i < loops; i++)
   {
      if (read(fd, block, 1024) != 1024)
      {
         (void)fprintf(stderr, "Failed to read() from %s : %s\n",
                       argv[1], strerror(errno));
         exit(-1);
      }
      if (scp_write(block, 1024) == -1)
      {
         (void)fprintf(stderr, "scp_write() %s failed\n", argv[1]);
         exit(-1);
      }
      fprintf(stdout, "*");
      fflush(stdout);
   }
   if (rest > 0)
   {
      if (read(fd, block, rest) != rest)
      {
         (void)fprintf(stderr, "Failed to read() from %s : %s\n",
                       argv[1], strerror(errno));
         exit(-1);
      }
      if (scp_write(block, rest) == -1)
      {
         (void)fprintf(stderr, "scp_write() %s failed\n", argv[1]);
         exit(-1);
      }
   }
   fprintf(stdout, "*\n");
   fflush(stdout);
   (void)close(fd);
   if (scp_close_file() == -1)
   {
      (void)fprintf(stderr, "scp_close_file() %s failed\n", argv[1]);
      exit(-1);
   }
   scp_quit();

   return(0);
}