struct config_tag * wcplg_open_sftp_session(char *userhost, char *user, char *pass, int portnumber) { wcplg_set_last_error_msg(NULL); connectMsg = userhost; if (ProgressProc("connecting", connectMsg, 0) == 1) { wcplg_set_last_error_msg("cancel by user"); return RESULT_ERR; } if (!user && !pass && !portnumber) { if (!cfg.host[0]) do_defaults(userhost, &cfg); userhost = cfg.host; user = cfg.username; portnumber = cfg.port; loaded_session = 1; } else { console_password = dupstr(pass); flags = 0; //FLAG_STDERR | FLAG_INTERACTIVE; cmdline_tooltype = TOOLTYPE_FILETRANSFER; //ssh_get_line = &console_get_line; do_defaults(NULL, &cfg); } // init_winsock(); sk_init(); back = NULL; if (userhost) { if (psftp_connect(userhost, user, portnumber)) { return RESULT_ERR; } if (1 == ProgressProc("connecting", connectMsg, 99)) return RESULT_ERR; if (do_sftp_init()) { return RESULT_ERR; } } else { printf("psftp: no hostname specified; use \"open host.name\" to connect\n"); return RESULT_ERR; } ISinitT = 1; disconnected = 0; cfg.sftp4tc.selectedSession = selectedSession; return &cfg; }
static int sftp_cmd_open(struct sftp_command *cmd) { if (back != NULL) { printf("psftp: already connected\n"); return 0; } if (cmd->nwords < 2) { printf("open: expects a host name\n"); return 0; } if (psftp_connect(cmd->words[1], NULL, 0)) { back = NULL; /* connection is already closed */ return -1; /* this is fatal */ } do_sftp_init(); return 1; }
int wcplg_open_sftp_session(char *userhost, char *user, char *pass, int portnumber) { wcplg_set_last_error_msg(NULL); if (ProgressProc("", "", 0) == 1) { wcplg_set_last_error_msg("cancel by user"); return RESULT_ERR; } console_password = dupstr(pass); flags = 0; //FLAG_STDERR | FLAG_INTERACTIVE; cmdline_tooltype = TOOLTYPE_FILETRANSFER; ssh_get_line = &console_get_line; do_defaults(NULL, &cfg); init_winsock(); sk_init(); back = NULL; if (userhost) { if (psftp_connect(userhost, user, portnumber)) { return RESULT_ERR; } if (do_sftp_init()) { return RESULT_ERR; } } else { printf ("psftp: no hostname specified; use \"open host.name\" to connect\n"); return RESULT_ERR; } ISinitT = 1; return RESULT_OK; }
/* * Main program. Parse arguments etc. */ int main(int argc, char *argv[]) { int i; int portnumber = 0; char *userhost, *user; int mode = 0; int modeflags = 0; char *batchfile = NULL; flags = FLAG_STDERR | FLAG_INTERACTIVE; ssh_get_line = &console_get_line; init_winsock(); sk_init(); userhost = user = NULL; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { if (userhost) usage(); else userhost = dupstr(argv[i]); } else if (strcmp(argv[i], "-v") == 0) { verbose = 1, flags |= FLAG_VERBOSE; } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0) { usage(); } else if (strcmp(argv[i], "-l") == 0 && i + 1 < argc) { user = argv[++i]; } else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) { portnumber = atoi(argv[++i]); } else if (strcmp(argv[i], "-pw") == 0 && i + 1 < argc) { console_password = argv[++i]; } else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) { mode = 1; batchfile = argv[++i]; } else if (strcmp(argv[i], "-bc") == 0) { modeflags = modeflags | 1; } else if (strcmp(argv[i], "-batch") == 0) { console_batch_mode = TRUE; } else if (strcmp(argv[i], "-be") == 0) { modeflags = modeflags | 2; } else if (strcmp(argv[i], "--") == 0) { i++; break; } else { usage(); } } argc -= i; argv += i; back = NULL; /* * If a user@host string has already been provided, connect to * it now. */ if (userhost) { if (psftp_connect(userhost, user, portnumber)) return 1; do_sftp_init(); } else { printf("psftp: no hostname specified; use \"open host.name\"" " to connect\n"); } do_sftp(mode, modeflags, batchfile); if (back != NULL && back->socket() != NULL) { char ch; back->special(TS_EOF); sftp_recvdata(&ch, 1); } WSACleanup(); random_save_seed(); return 0; }
/** * Creates SFTP channel that closes itself in a thread-safe manner * when it goes out of scope. */ sftp_channel_state(session_state& session) : m_session(session), m_sftp(do_sftp_init(session_ref())) {}