//- (BOOL)uploadFile;
- (void)setStatus:(NSString *)msg isError:(BOOL)error;
+- (void)readChannel:(LIBSSH2_CHANNEL *)channel;
+
@end
}
}
+/**
+ * Reads through a channel (in non-blocking) mode until there is no more left to read
+ * and then it returns. This calls sleep(1) so that the channel can have time to process.
+ * Be sure this is threaded otherwis the interface will stall.
+ */
+- (void)readChannel:(LIBSSH2_CHANNEL *)channel
+{
+ libssh2_channel_set_blocking(channel, 0);
+
+ char buf[1024];
+ int numbytes;
+ do
+ {
+ memset(&buf, '\0', sizeof(buf));
+ sleep(1);
+ numbytes = libssh2_channel_read(channel, buf, sizeof(buf));
+ } while (numbytes > 0);
+}
+
/**
* Sends an item to the printer
*/
[self setStatus:@"Opened remote SSH shell" isError:NO];
- libssh2_channel_flush_ex(channel, LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL);
-
- /*
- char *e = malloc(1024 * sizeof(char));
- libssh2_session_last_error(ssh, &e, NULL, 0);
- NSLog(@"e = %s", e);
- */
-
- libssh2_channel_set_blocking(channel, 0);
-
- char b[1024];
- int r;
- do
- {
- memset(&b, '\0', sizeof(b));
- sleep(1);
- r = libssh2_channel_read(channel, b, sizeof(b));
- NSLog(@"b(%i) = %s", r, b);
- } while (r > 0);
+ // read the banner
+ [self readChannel:channel];
char *cmd = "touch /u17/ugrad/rsesek/temp.foo\r\n\0";
- NSLog(@"numbytes = %i", libssh2_channel_write(channel, cmd, sizeof(char) * strlen(cmd)));
-
- do
- {
- memset(&b, '\0', sizeof(b));
- sleep(1);
- r = libssh2_channel_read(channel, b, sizeof(b));
- NSLog(@"b(%i) = %s", r, b);
- } while (r > 0);
+ libssh2_channel_write(channel, cmd, sizeof(char) * strlen(cmd));
+ [self readChannel:channel];
[self setStatus:@"Printed!" isError:NO];