+ }
+
+ // Strip all trailing nonprintables (crlf)
+ buf[i] = 0;
+}
+
+
+// send line to server - implemented in terms of serv_write()
+void serv_puts(int serv_sock, char *buf) {
+ serv_write(serv_sock, buf, strlen(buf));
+ serv_write(serv_sock, "\n", 1);
+}
+
+
+// send formatted printable data to the server
+void serv_printf(int serv_sock, const char *format, ...) {
+ va_list arg_ptr;
+ char buf[1024];
+
+ va_start(arg_ptr, format);
+ if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
+ buf[sizeof buf - 2] = '\n';
+ serv_write(serv_sock, buf, strlen(buf));
+ va_end(arg_ptr);
+}
+
+
+// You know what main() does. If you don't, you shouldn't be trying to understand this program.
+int main(int argc, char *argv[]) {
+ char ctdldir[PATH_MAX]=CTDLDIR;
+ char yesno[2];
+ int cmdexit = 0; // when something fails, set cmdexit to nonzero, and skip to the end
+ char buf[PATH_MAX];
+
+ char remote_user[128];
+ char remote_host[128];
+ char remote_pass[128];
+ char *remote_port = "504";
+
+ int linecount = 0;
+ int a;
+ int remote_server_socket = (-1);
+ int local_admin_socket = (-1);
+ int progress = 0;
+
+ // Parse command line
+ while ((a = getopt(argc, argv, "h:")) != EOF) {
+ switch (a) {
+ case 'h':
+ strcpy(ctdldir, optarg);
+ break;
+ default:
+ fprintf(stderr, "ctdlmigrate: usage: ctdlmigrate [-h server_dir]\n");
+ return(1);