diff -urN hasciicam-1.0//hasciicam.c /home/michele/Devel/hasciicam-1.0//hasciicam.c
--- hasciicam-1.0//hasciicam.c	2008-09-22 17:28:48.000000000 +0200
+++ /home/michele/Devel/hasciicam-1.0//hasciicam.c	2010-10-04 00:00:51.000000000 +0200
@@ -45,7 +45,7 @@
 
 #include <aalib.h>
 #include <ftplib.h>
-
+#include <libssh/libssh.h>
 
 
 /* hasciicam modes */
@@ -76,9 +76,11 @@
 "-s --size         ascii image size WxH      - default 96x72\n"
 "-o --aafile       dumped file               - default hasciicam.[txt|html]\n"
 "-f --ftp          ie: :user%pass@host:dir   - default none\n"
+"-p --scp          ie: user%pass@host:dir    - default none\n"
 "-D --daemon       run in background         - default foregrond\n"
 "-U --uid          setuid (int)              - default current\n"
 "-G --gid          setgid (int)              - default current\n"
+"-t --times        number of frames to catch - default infinite\n"
 "rendering options:\n"
 "-S --font-size    html font size (1-4)      - default 1\n"
 "-a --font-face    html font to use          - default courier\n"
@@ -102,6 +104,8 @@
   {"size", required_argument, NULL, 's'},
   {"aafile", required_argument, NULL, 'o'},
   {"ftp", required_argument, NULL, 'f'},
+  {"scp", required_argument, NULL, 'p'},
+  {"times", required_argument, NULL, 't'},
   {"daemon", no_argument, NULL, 'D'},
   {"font-size", required_argument, NULL, 'S'},
   {"font-face", required_argument, NULL, 'a'},
@@ -120,16 +124,18 @@
   {0, 0, 0, 0}
 };
 
-char *short_options = "hHvqm:d:i:n:s:f:DS:a:r:o:b:c:g:IB:F:O:Q:U:G:";
+char *short_options = "hHvqm:d:i:n:s:f:p:t:DS:a:r:o:b:c:g:IB:F:O:Q:U:G:";
 
 /* default configuration */
 int quiet = 0;
 int mode = 0;
 int useftp = 0;
+int usessh = 0;
 int input = 1;
 int daemon_mode = 0;
 int invert = 0;
 int norm = VIDEO_MODE_AUTO;
+int times = -1;
 
 struct geometry {
   int w, h, size;
@@ -158,6 +164,16 @@
 int ftp_passive;
 netbuf *ftpconn = NULL;
 
+/* scp stuff */
+ssh_session ssh_sess;
+ssh_scp scp_sess;
+char ssh_uri[512];
+char ssh_user[256];
+char ssh_host[256];
+char ssh_dir[256];
+char ssh_pass[256];
+
+
 int uid = -1;
 int gid = -1;
 
@@ -555,6 +571,9 @@
     case 'r':
       refresh = atoi (optarg);
       break;
+    case 't':
+      times = atoi (optarg);
+      break;
     case 'o':
       if(mode>0)
 	strncpy(aafile,optarg,256);
@@ -568,6 +587,15 @@
 	fprintf (stderr,
 		 "heek, ftp option makes no sense with live mode!\n");
       break;
+    case 'p':
+      if (mode==0 || useftp==0) {
+        strncpy(ssh_uri,optarg,512);
+        usessh = 1;
+      } 
+      else
+        fprintf(stderr,
+                "ssh option make no sense with live mode or with ftp\n");
+      break;
     case 'D':
       daemon_mode = 1;
       break;
@@ -649,13 +677,49 @@
     if((pp-p)==0) strcpy(ftp_dir,".");
     else strncpy(ftp_dir,pp,256);
   }
+  else if (usessh) {
+    char *p, *pp;
+    p = pp = ssh_uri;
 
+    /* get the user and check if a password has been specified */
+    while (*p != '@') {
+      if(*p == '%') { /* pass found, get it */
+	*p = '\0'; strncpy(ssh_user,pp,256);
+	pp = p+1;
+      }
+      if ((p - pp) < 256) p++;
+      else {
+	fprintf (stderr,"Error: malformed ssh command: %s\n", ftp);
+	exit (0); }
+    } /* here we have the username */
+     *p = '\0'; strncpy(ssh_pass,pp,256);
+    p++; pp = p;
+    
+    while (*p != ':') {
+      if ((pp - p) < 256) p++;
+      else {
+	fprintf (stderr,"Error: malformed ssh command: %s\n", ftp);
+	exit (0); }
+    } /* here the host */
+    *p = '\0'; strncpy(ssh_host,pp,256);
+    p++; pp = p;
+
+    while (*p != '\0' && *p != '\n') {
+      if ((pp - p) < 256) p++;
+      else {
+	fprintf (stderr,"Error: malformed ftp command: %s\n", ftp);
+	exit (0); }
+    }
+    if((pp-p)==0) strcpy(ssh_dir,".");
+    else strncpy(ssh_dir,pp,256);
+  }
 }
 
 /* here we go (chmicl broz rlz! :)*/
 
 int
 main (int argc, char **argv) {
+  int counter = 0;
   /* reminder:
      !!! grabbing height & width should be double
      the ascii context width and height !!! */
@@ -765,6 +829,45 @@
       break;
     }
 
+  while (usessh)
+    {
+      char temp[160];
+      int rc;
+      fprintf (stderr, "scp push on scp://%s - %s @ %s : %s\n", ssh_user, ssh_pass, ssh_host, ssh_dir);
+      ssh_sess = ssh_new();
+      if (ssh_sess == NULL) {
+	fprintf(stderr,"ssh_new failed\n");
+	usessh = 0; break;
+      }
+
+      ssh_options_set(ssh_sess, SSH_OPTIONS_HOST, ssh_host);
+
+      rc = ssh_connect(ssh_sess);
+      if (rc != SSH_OK)
+      {
+        fprintf(stderr, "Error connecting : %s\n", ssh_get_error(ssh_sess));
+        ssh_free(ssh_sess);
+        usessh = 0; break;
+      }
+
+      rc = ssh_is_server_known(ssh_sess);
+      if (rc != SSH_SERVER_KNOWN_OK) {
+        fprintf(stderr, "Error connecting : %s\n", ssh_get_error(ssh_sess));
+        ssh_free(ssh_sess);
+        usessh = 0; break;  
+      }
+
+      fprintf (stderr, "scp push on scp://%s - %s\n", ssh_user, ssh_pass);
+      rc = ssh_userauth_password(ssh_sess, ssh_user, ssh_pass);
+      if (rc != SSH_OK) {
+        fprintf(stderr, "Error authenticating: %s\n", ssh_get_error(ssh_sess));
+        ssh_free(ssh_sess);
+        usessh = 0; break;  
+      }
+
+      break;
+    }
+
 
   ascii_rndparms->bright = aa_geo.bright;
   ascii_rndparms->contrast = aa_geo.contrast;
@@ -813,13 +916,78 @@
       if(!FtpRename("scolopendro",aafile,ftpconn))
 	fprintf(stderr,"Error in ftp rename %s\n",FtpLastResponse(ftpconn));
     }
-  
+    if (usessh) {
+      int rc,r,fd;
+      int total=0;
+      struct stat buf;
+      char buffer[16384];
+
+      r = stat(aafile, &buf);
+      if (r < 0) {
+        fprintf(stderr, "Can't stat: %s (%s)\n", aafile, strerror(errno));
+        break;
+      }
+
+      scp_sess = ssh_scp_new(ssh_sess, SSH_SCP_WRITE, ssh_dir);
+      if (scp_sess == NULL) {
+        fprintf(stderr, "Error allocating scp session\n");
+        break;
+      }
+
+      rc = ssh_scp_init(scp_sess);
+      if (rc != SSH_OK) {
+        fprintf(stderr, "Error initializing scp session: %s\n", ssh_get_error(ssh_sess));
+        break;
+      }
+      
+
+      rc = ssh_scp_push_file(scp_sess, aafile, buf.st_size, S_IRUSR | S_IWUSR);
+      if (rc != SSH_OK) {
+        fprintf(stderr, "Can't open remote file: %s\n", ssh_get_error(ssh_sess));
+        break;
+      }
+
+      fd=open(aafile, O_RDONLY);
+      if (fd<0) {
+        fprintf(stderr,"Error opening file: %s\n",strerror(errno));
+        break;
+      }
+      do {
+        fprintf(stderr, "1) r %i, total %i, size %lu\n", r, total, buf.st_size);
+        r=read(fd,buffer,sizeof(buffer));
+        if (r == 0)
+          break;
+        if (r < 0) {
+          fprintf(stderr,"Error reading file: %s\n",strerror(errno));
+          break;
+        }
+        rc=ssh_scp_write(scp_sess,buffer,r);
+        if(rc == SSH_ERROR){
+          fprintf(stderr,"Error writing in scp: %s\n",ssh_get_error(ssh_sess));
+          break;
+        } 
+        total += r;
+        fprintf(stderr, "2) r %i, total %i, size %lu\n", r, total, buf.st_size);
+       
+      } while (total < buf.st_size);
+      close(fd);
+    }
+    counter += 1;
+    if (times != -1 && counter > times)
+      break;
   }
 
   /* CLEAN EXIT */
   
   if(useftp)
     FtpClose(ftpconn);
+  if(usessh) {
+    
+    ssh_scp_close(scp_sess);
+    ssh_scp_free(scp_sess);
+    ssh_disconnect(ssh_sess);
+    ssh_free(ssh_sess);
+  }
 
   aa_close(ascii_context);
   //  free(ascii_rndparms);

