Index: branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 854)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 860)
@@ -283,5 +283,7 @@
     }
   }while(!sftp_handle);
+#ifdef SSH_DEBUG
   fprintf(stderr, "libssh2_sftp_open() is done, get file information\n");
+#endif
   do {
   rc = libssh2_sftp_stat_ex(sessions[cnt]->sftp_session, targetPath, strlen(targetPath),
@@ -295,8 +297,10 @@
   else
     {
+#ifdef SSH_DEBUG
       fprintf(stderr, "Stat Data: RetCode=%d\n", rc);
       fprintf(stderr, "Stat Data: Size=%llu\n", attrs.filesize);
       fprintf(stderr, "Stat Data: Perm=%lx\n",  attrs.permissions);
       fprintf(stderr, "Stat Data: mtime=%lu\n",  attrs.mtime);
+#endif
       if(rc==0)
 	break;
@@ -348,4 +352,6 @@
       return false;
     }
+    if(!sessions[cnt]->sftp_session)
+      zSleep(10);
   } while (!sessions[cnt]->sftp_session);
 
@@ -363,4 +369,6 @@
       return false;
     }
+    if(!sftp_handle)
+      zSleep(10);
   } while (!sftp_handle);
   start = time(NULL);
@@ -432,4 +440,6 @@
       return -1;
     }
+    if(!sessions[cnt]->sftp_session)
+      zSleep(10);
   } while (!sessions[cnt]->sftp_session);
   do {
@@ -482,5 +492,5 @@
       return -1;
     }
- 
+    
   } while (1);
   duration = (int)(time(NULL)-start);
@@ -503,33 +513,19 @@
   int exitcode;
   char *exitsignal=(char *)"none";
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while( (channel = libssh2_channel_open_session(sessions[cnt]->session)) == NULL &&
 	 libssh2_session_last_error(sessions[cnt]->session,NULL,NULL,0) == LIBSSH2_ERROR_EAGAIN ) {
-    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-    fflush(stderr);
-      waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
-  }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
+    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
+  }
   if( channel == NULL ){
     fprintf(stderr,"Error\n");
     return -1;
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while( (rc = libssh2_channel_exec(channel, command)) == LIBSSH2_ERROR_EAGAIN ) {
-    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-    fflush(stderr);
     waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   if( rc != 0 ) {
     fprintf(stderr,"Error\n");
     return -1;
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
 
   map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
@@ -539,6 +535,4 @@
   FILE* logFile=fopen(logPath,"wb");
   free(logPath);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while(true){
     int rc;
@@ -563,16 +557,8 @@
       break;
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   fclose(logFile);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   exitcode = 127;
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while( (rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN )
     waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   
   if( rc == 0 ) {
@@ -581,6 +567,4 @@
 				    NULL, NULL, NULL, NULL, NULL);
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   
   if (exitsignal)
@@ -588,6 +572,4 @@
   else
     fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   
   libssh2_channel_free(channel);
@@ -664,5 +646,5 @@
     }
   }
-#ifdef DEBUG  
+#ifdef SSH_DEBUG  
   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
   fflush(stderr);
@@ -682,5 +664,5 @@
     return false;
   }
-#ifdef DEBUG
+#ifdef SSH_DEBUG
   fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
   fflush(stderr);
@@ -700,5 +682,7 @@
 	getMapArray(queueMaps->content,"targetPath",i)
       };
+#ifdef SSH_DEBUG      
       fprintf(stderr,"*** %s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value);
+#endif      
       /**/zooLock* lck;
       if((lck=lockFile(*conf,argv[1]->value,'w'))!=NULL){/**/
