summaryrefslogtreecommitdiff
path: root/src/rcopy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rcopy.c')
-rw-r--r--src/rcopy.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/rcopy.c b/src/rcopy.c
new file mode 100644
index 0000000..8858f07
--- /dev/null
+++ b/src/rcopy.c
@@ -0,0 +1,43 @@
+#if HAVE_STDBOOL_H
+#include <stdbool.h>
+#endif
+
+#include "rexec.h"
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+static char *alloc_cmd(const char *restrict format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ int len = vsnprintf(NULL, 0, format, ap);
+ va_end(ap);
+
+ char *buf = malloc(len+1);
+ va_start(ap, format);
+ (void)vsnprintf(buf, len+1, format, ap);
+ va_end(ap);
+
+ return buf;
+}
+
+int sk_rcopy_file(
+ const char *restrict src, const char *restrict target_host,
+ const char *restrict dst) {
+ char *remote_cmd = alloc_cmd("cat >%s && chmod 0700 %s", dst, dst);
+ FILE *sfil = fopen(src, "r");
+
+ /* TODO: set correct stdout and stderr */
+ int rv = sk_rexec_command(
+ target_host, remote_cmd,
+ fileno(sfil), fileno(stdout), fileno(stderr),
+ NULL);
+
+ /* clean up */
+ fclose(sfil);
+ free(remote_cmd);
+
+ return rv;
+}