+/* Example using wrappi to access a remote server and read a file. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include <wrappi.h>
+
+int
+main (int argc, char *argv[])
+{
+ wrap_h *w;
+ const char *hostname;
+
+ /* We're going to use ssh to access the remote server. This is
+ * automatic but we need a hostname on the command line.
+ */
+ if (argc < 2) {
+ fprintf (stderr, "missing parameter: give the remote hostname\n");
+ exit (EXIT_FAILURE);
+ }
+ hostname = argv[1];
+
+ w = wrap_create ();
+ if (!w) {
+ fprintf (stderr, "could not allocate wrappi handle\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Set the connection method to ssh to the remote host. If you
+ * simply comment out the next two lines, then wrappi will run the
+ * commands on the local machine.
+ */
+ wrap_set_scheme (w, "ssh");
+ wrap_set_hostname (w, hostname);
+
+ /* Connect the handle. Because we didn't set any error handler,
+ * errors will be printed on stderr, so we can just exit if we get
+ * an error.
+ */
+ wrap_connect (w);
+ if (wrap_error (w))
+ exit (EXIT_FAILURE);
+
+#if 0
+ /* Read a file from the remote machine. Most Un*x-like machines
+ * should have /etc/issue.
+ */
+ printf ("--- contents of /etc/issue from %s ---\n", hostname);
+ wrap_download (w, "/etc/issue", "/dev/stdout");
+ if (wrap_error (w))
+ exit (EXIT_FAILURE);
+#else
+ int64_t size = wrap_filesize (w, "/etc/issue");
+ if (wrap_error (w))
+ exit (EXIT_FAILURE);
+ printf ("size of /etc/issue = %" PRIi64 " bytes\n", size);
+#endif
+
+ wrap_close (w);
+
+ exit (EXIT_SUCCESS);
+}