这篇教程C++ ssh_get_error函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中ssh_get_error函数的典型用法代码示例。如果您正苦于以下问题:C++ ssh_get_error函数的具体用法?C++ ssh_get_error怎么用?C++ ssh_get_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了ssh_get_error函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: throwvoid clSSH::DoOpenChannel() throw(clException){ if(m_channel) return; m_channel = ssh_channel_new(m_session); if(!m_channel) { throw clException(ssh_get_error(m_session)); } int rc = ssh_channel_open_session(m_channel); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); } rc = ssh_channel_request_pty(m_channel); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); } rc = ssh_channel_change_pty_size(m_channel, 80, 24); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); } rc = ssh_channel_request_shell(m_channel); if(rc != SSH_OK) { throw clException(ssh_get_error(m_session)); }}
开发者ID:GaganJotSingh,项目名称:codelite,代码行数:29,
示例2: ssh_connect/** Connecting to the target machine. @param none @return none*/bool SSHSession::connect(const char *username, const char *password) { auto rc = ssh_connect(mSSHSession); if (rc != SSH_OK) { auto error_msg = ssh_get_error(mSSHSession); throw std::runtime_error(error_msg); } else { auto isKnown = verifyKnownHost(mSSHSession); if (isKnown) { connected = true; // authenticating the user rc = authenticateUser(mSSHSession, username, password); if (rc != SSH_AUTH_SUCCESS) { throw std::runtime_error(ssh_get_error(mSSHSession)); } else { std::cout << "Successfully login" << std::endl; return true; } } else { throw std::runtime_error("Server not known."); } }}
开发者ID:bepitulaz,项目名称:LalaPi,代码行数:32,
示例3: pkd_channel_openreq_cbstatic ssh_channel pkd_channel_openreq_cb(ssh_session s, void *userdata) { ssh_channel c = NULL; ssh_channel *out = (ssh_channel *) userdata; /* assumes pubkey authentication has already succeeded */ pkdout("pkd_channel_openreq_cb/n"); c = ssh_channel_new(s); if (c == NULL) { pkderr("ssh_channel_new: %s/n", ssh_get_error(s)); return NULL; } ssh_callbacks_init(&pkd_channel_cb); pkd_channel_cb.userdata = userdata; if (ssh_set_channel_callbacks(c, &pkd_channel_cb) != SSH_OK) { pkderr("ssh_set_channel_callbacks: %s/n", ssh_get_error(s)); ssh_channel_free(c); c = NULL; } *out = c; return c;}
开发者ID:ShiftMediaProject,项目名称:libssh,代码行数:26,
示例4: shellvoid shell(SSH_SESSION *session){ CHANNEL *channel; struct termios terminal_local; int interactive=isatty(0); channel = channel_new(session); if(interactive){ tcgetattr(0,&terminal_local); memcpy(&terminal,&terminal_local,sizeof(struct termios)); } if(channel_open_session(channel)){ printf("error opening channel : %s/n",ssh_get_error(session)); return; } chan=channel; if(interactive){ channel_request_pty(channel); sizechanged(); } if(channel_request_shell(channel)){ printf("Requesting shell : %s/n",ssh_get_error(session)); return; } if(interactive){ cfmakeraw(&terminal_local); tcsetattr(0,TCSANOW,&terminal_local); setsignal(); } signal(SIGTERM,do_cleanup); select_loop(session,channel);}
开发者ID:BackupTheBerlios,项目名称:libssh-svn,代码行数:30,
示例5: cockpit_ssh_connectstatic const gchar *cockpit_ssh_connect (CockpitSshData *data){ const gchar *problem; int rc; /* * If connect_done is set prematurely by another thread then the * connection attempt was cancelled. */ rc = ssh_connect (data->session); if (rc != SSH_OK) { if (g_atomic_int_get (data->connecting)) g_message ("%s: couldn't connect: %s", data->logname, ssh_get_error (data->session)); return "no-host"; } g_debug ("%s: connected", data->logname); if (!data->ignore_key) { problem = verify_knownhost (data); if (problem != NULL) return problem; } /* The problem returned when auth failure */ problem = cockpit_ssh_authenticate (data); if (problem != NULL) return problem; data->channel = ssh_channel_new (data->session); g_return_val_if_fail (data->channel != NULL, NULL); rc = ssh_channel_open_session (data->channel); if (rc != SSH_OK) { if (g_atomic_int_get (data->connecting)) g_message ("%s: couldn't open session: %s", data->logname, ssh_get_error (data->session)); return "internal-error"; } rc = ssh_channel_request_exec (data->channel, data->command); if (rc != SSH_OK) { if (g_atomic_int_get (data->connecting)) g_message ("%s: couldn't execute command: %s: %s", data->logname, data->command, ssh_get_error (data->session)); return "internal-error"; } g_debug ("%s: opened channel", data->logname); /* Success */ return NULL;}
开发者ID:leospol,项目名称:cockpit,代码行数:60,
示例6: throwvoid clSFTP::Write(const wxMemoryBuffer& fileContent, const wxString& remotePath) throw(clException){ if(!m_sftp) { throw clException("SFTP is not initialized"); } int access_type = O_WRONLY | O_CREAT | O_TRUNC; sftp_file file; wxString tmpRemoteFile = remotePath; tmpRemoteFile << ".codelitesftp"; file = sftp_open(m_sftp, tmpRemoteFile.mb_str(wxConvUTF8).data(), access_type, 0644); if(file == NULL) { throw clException(wxString() << _("Can't open file: ") << tmpRemoteFile << ". " << ssh_get_error(m_ssh->GetSession()), sftp_get_error(m_sftp)); } char* p = (char*)fileContent.GetData(); const int maxChunkSize = 65536; wxInt64 bytesLeft = fileContent.GetDataLen(); while(bytesLeft > 0) { wxInt64 chunkSize = bytesLeft > maxChunkSize ? maxChunkSize : bytesLeft; wxInt64 bytesWritten = sftp_write(file, p, chunkSize); if(bytesWritten < 0) { sftp_close(file); throw clException(wxString() << _("Can't write data to file: ") << tmpRemoteFile << ". " << ssh_get_error(m_ssh->GetSession()), sftp_get_error(m_sftp)); } bytesLeft -= bytesWritten; p += bytesWritten; } sftp_close(file); // Unlink the original file if it exists bool needUnlink = false; { // Check if the file exists sftp_attributes attr = sftp_stat(m_sftp, remotePath.mb_str(wxConvISO8859_1).data()); if(attr) { needUnlink = true; sftp_attributes_free(attr); } } if(needUnlink && sftp_unlink(m_sftp, remotePath.mb_str(wxConvUTF8).data()) < 0) { throw clException(wxString() << _("Failed to unlink file: ") << remotePath << ". " << ssh_get_error(m_ssh->GetSession()), sftp_get_error(m_sftp)); } // Rename the file if(sftp_rename(m_sftp, tmpRemoteFile.mb_str(wxConvUTF8).data(), remotePath.mb_str(wxConvUTF8).data()) < 0) { throw clException(wxString() << _("Failed to rename file: ") << tmpRemoteFile << " -> " << remotePath << ". " << ssh_get_error(m_ssh->GetSession()), sftp_get_error(m_sftp)); }}
开发者ID:292388900,项目名称:codelite,代码行数:60,
示例7: scp_testint scp_test(ssh_session session, ssh_scp scp){ int rc; const char *helloworld = "Hello, world!/n"; int length = strlen(helloworld); rc = ssh_scp_push_directory(scp, "helloworld", S_IRWXU); if(rc != SSH_OK) { fprintf(stderr, "Can't create remote directory: %s/n", ssh_get_error(session)); return rc; } rc = ssh_scp_push_file(scp, "helloworld", length, S_IRUSR | S_IWUSR); if(rc != SSH_OK) { fprintf(stderr, "Can't open remote file: %s/n", ssh_get_error(session)); return rc; } rc = ssh_scp_write(scp, helloworld, length); //ssh_option_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost"); if(rc != SSH_OK) { fprintf(stderr, "Can't write remote file: %s/n", ssh_get_error(session)); return rc; } return SSH_OK;}
开发者ID:novice555,项目名称:cpe24-project,代码行数:30,
示例8: dispatch_eofstatic voiddispatch_eof (CockpitSshTransport *self){ g_assert (!self->sent_eof); switch (ssh_channel_send_eof (self->data->channel)) { case SSH_AGAIN: g_debug ("%s: will send eof later", self->logname); break; case SSH_OK: g_debug ("%s: sent eof", self->logname); self->sent_eof = TRUE; break; default: if (ssh_get_error_code (self->data->session) == SSH_REQUEST_DENIED) { g_debug ("%s: couldn't send eof: %s", self->logname, ssh_get_error (self->data->session)); self->sent_eof = TRUE; /* channel is already closed */ } else { g_warning ("%s: couldn't send eof: %s", self->logname, ssh_get_error (self->data->session)); close_immediately (self, "internal-error"); } break; }}
开发者ID:leospol,项目名称:cockpit,代码行数:30,
示例9: privatekey_from_file/** * Authenticate in the SSH server with key * @param QString private_key the private key to use for connect in the SSH server * @param QString password the password to use for connect in the SSH server (passphrase of the private key) * @return bool true if it's ok, false else * @todo test with a private key with passphrase */bool Kssh::authenticateKey(QString private_key, QString password){ ssh_string public_key_to_use; ssh_private_key private_key_to_use; int auth; private_key_to_use = privatekey_from_file(this->m_session, private_key.toStdString().c_str(), 0, password.toStdString().c_str()); if (private_key_to_use == NULL) { Klog::error(QString("Fatal error while get the private key : ") + QString(ssh_get_error(this->m_session))); return false; } // get the public key public_key_to_use = publickey_to_string(publickey_from_privatekey(private_key_to_use)); // try to authenticate auth = ssh_userauth_pubkey(this->m_session, NULL, public_key_to_use, private_key_to_use); if (auth == SSH_AUTH_SUCCESS) { // clear the keys of the memory privatekey_free(private_key_to_use); string_free(public_key_to_use); // it's ok return true; } else if (auth == SSH_AUTH_DENIED || auth == SSH_AUTH_PARTIAL) { Klog::warning(QString("Authenticated denied with this key")); return false; } else if (auth == SSH_AUTH_ERROR) { Klog::error(QString("Fatal error in authenticated with key : ") + QString(ssh_get_error(this->m_session))); return false; } return false;}
开发者ID:leblanc-simon,项目名称:qlaunchoverssh,代码行数:42,
示例10: ssh_options_set_hostSSH_SESSION *connect_host(const char *hostname){ SSH_SESSION *session; SSH_OPTIONS *options; int auth=0; int state; options=ssh_options_new(); ssh_options_set_host(options,hostname); session=ssh_new(); ssh_set_options(session,options); if(ssh_connect(session)){ fprintf(stderr,"Connection failed : %s/n",ssh_get_error(session)); ssh_disconnect(session); return NULL; } state = ssh_session_is_known_server(session); switch(state){ case SSH_SERVER_KNOWN_OK: break; /* ok */ case SSH_SERVER_KNOWN_CHANGED: fprintf(stderr,"Host key for server changed : server's one is now :/n"); fprintf(stderr,"For security reason, connection will be stopped/n"); ssh_disconnect(session); ssh_finalize(); return NULL; case SSH_SERVER_FOUND_OTHER: fprintf(stderr,"The host key for this server was not found but an other type of key exists./n"); fprintf(stderr,"An attacker might change the default server key to confuse your client" "into thinking the key does not exist/n" "We advise you to rerun the client with -d or -r for more safety./n"); ssh_disconnect(session); ssh_finalize(); return NULL; case SSH_SERVER_NOT_KNOWN: fprintf(stderr,"The server is unknown. Leaving now"); ssh_disconnect(session); return NULL; case SSH_SERVER_ERROR: fprintf(stderr,"%s",ssh_get_error(session)); ssh_disconnect(session); return NULL; } ssh_userauth_none(session, NULL); auth=ssh_userauth_autopubkey(session, NULL); if(auth==SSH_AUTH_ERROR){ fprintf(stderr,"Authenticating with pubkey: %s/n",ssh_get_error(session)); ssh_disconnect(session); return NULL; } if(auth!=SSH_AUTH_SUCCESS){ fprintf(stderr,"Authentication failed: %s/n",ssh_get_error(session)); ssh_disconnect(session); return NULL; } ssh_log(session, SSH_LOG_FUNCTIONS, "Authentication success"); return session;}
开发者ID:Paxxi,项目名称:libssh,代码行数:60,
示例11: host_ SSH::SSH(const std::string& host, const std::string& user, const std::string& pass, const std::string port): host_(host),user_(user),pass_(pass),sftp_(0) { std::string timeout = getEnv(envTIMEOUT); timeout_ = atol(timeout.c_str()); if (timeout_ == 0) { throw Error(1, "Timeout Environmental Variable must be a positive integer."); } session_ = ssh_new(); if (session_ == NULL) { throw Error(1, "Unable to create the the ssh session"); } // try to connect ssh_options_set(session_, SSH_OPTIONS_HOST, host_.c_str()); ssh_options_set(session_, SSH_OPTIONS_USER, user_.c_str()); ssh_options_set(session_, SSH_OPTIONS_TIMEOUT, &timeout_); if (port != "") ssh_options_set(session_, SSH_OPTIONS_PORT_STR, port.c_str()); if (ssh_connect(session_) != SSH_OK) { throw Error(1, ssh_get_error(session_)); } // Authentication if (ssh_userauth_password(session_, NULL, pass_.c_str()) != SSH_AUTH_SUCCESS) { throw Error(1, ssh_get_error(session_)); } }
开发者ID:obklar,项目名称:exiv2,代码行数:28,
示例12: spatchint spatch(){ ssh_session session = NULL; ssh_bind sshbind = NULL; sthreadList* list = NULL; int port = SERVER_PORT; sshbind=ssh_bind_new(); //session=ssh_new(); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, KEYS_FOLDER "ssh_host_dsa_key"); ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key"); if (ssh_bind_listen(sshbind)<0) { printf("Error listening to socket: %s/n", ssh_get_error(sshbind)); return 1; } printf("Server start on port %d/n", port); while(1) { session=ssh_new(); if (ssh_bind_accept(sshbind, session) == SSH_ERROR) { printf("Error accepting a connection: %s/n", ssh_get_error(sshbind)); ssh_free(session); } else { list = newNodeList(list, session); if (pthread_create(&(list->thread), NULL, (void*)NewSessionLoop, (void*)&(list->sesData)) != 0) { sthreadList* tmp; ssh_disconnect(session); ssh_free(session); tmp = list; list = list->next; free(tmp); } } } if (session) ssh_free(session); cleanList(list); ssh_bind_free(sshbind); ssh_finalize(); return 0;}
开发者ID:bertonf,项目名称:NSP2,代码行数:56,
示例13: fetch_filesstatic int fetch_files(ssh_session session){ int size; char buffer[16384]; int mode; char *filename; int r; ssh_scp scp=ssh_scp_new(session, SSH_SCP_READ | SSH_SCP_RECURSIVE, "/tmp/libssh_tests/*"); if(ssh_scp_init(scp) != SSH_OK){ fprintf(stderr,"error initializing scp: %s/n",ssh_get_error(session)); return -1; } printf("Trying to download 3 files (a,b,d) and 1 directory (c)/n"); do { r=ssh_scp_pull_request(scp); switch(r){ case SSH_SCP_REQUEST_NEWFILE: size=ssh_scp_request_get_size(scp); filename=strdup(ssh_scp_request_get_filename(scp)); mode=ssh_scp_request_get_permissions(scp); printf("downloading file %s, size %d, perms 0%o/n",filename,size,mode); free(filename); ssh_scp_accept_request(scp); r=ssh_scp_read(scp,buffer,sizeof(buffer)); if(r==SSH_ERROR){ fprintf(stderr,"Error reading scp: %s/n",ssh_get_error(session)); return -1; } printf("done/n"); break; case SSH_ERROR: fprintf(stderr,"Error: %s/n",ssh_get_error(session)); return -1; case SSH_SCP_REQUEST_WARNING: fprintf(stderr,"Warning: %s/n",ssh_scp_request_get_warning(scp)); break; case SSH_SCP_REQUEST_NEWDIR: filename=strdup(ssh_scp_request_get_filename(scp)); mode=ssh_scp_request_get_permissions(scp); printf("downloading directory %s, perms 0%o/n",filename,mode); free(filename); ssh_scp_accept_request(scp); break; case SSH_SCP_REQUEST_ENDDIR: printf("End of directory/n"); break; case SSH_SCP_REQUEST_EOF: printf("End of requests/n"); goto end; } } while (1); end: return 0;}
开发者ID:CUEBoxer,项目名称:OpenStudio,代码行数:54,
示例14: open_locationstatic int open_location(struct location *loc, int flag){ if(loc->is_ssh && flag==WRITE){ loc->session=connect_ssh(loc->host,loc->user,verbosity); if(!loc->session){ fprintf(stderr,"Couldn't connect to %s/n",loc->host); return -1; } loc->scp=ssh_scp_new(loc->session,SSH_SCP_WRITE,loc->path); if(!loc->scp){ fprintf(stderr,"error : %s/n",ssh_get_error(loc->session)); return -1; } if(ssh_scp_init(loc->scp)==SSH_ERROR){ fprintf(stderr,"error : %s/n",ssh_get_error(loc->session)); ssh_scp_free(loc->scp); return -1; } return 0; } else if(loc->is_ssh && flag==READ){ loc->session=connect_ssh(loc->host, loc->user,verbosity); if(!loc->session){ fprintf(stderr,"Couldn't connect to %s/n",loc->host); return -1; } loc->scp=ssh_scp_new(loc->session,SSH_SCP_READ,loc->path); if(!loc->scp){ fprintf(stderr,"error : %s/n",ssh_get_error(loc->session)); return -1; } if(ssh_scp_init(loc->scp)==SSH_ERROR){ fprintf(stderr,"error : %s/n",ssh_get_error(loc->session)); ssh_scp_free(loc->scp); return -1; } return 0; } else { loc->file=fopen(loc->path,flag==READ ? "r":"w"); if(!loc->file){ if(errno==EISDIR){ if(chdir(loc->path)){ fprintf(stderr,"Error changing directory to %s: %s/n",loc->path,strerror(errno)); return -1; } return 0; } fprintf(stderr,"Error opening %s: %s/n",loc->path,strerror(errno)); return -1; } return 0; } return -1;}
开发者ID:CorneliuAndrei,项目名称:WHC-IDE,代码行数:52,
示例15: connect_sshssh_session connect_ssh(const char *host, const char *user,int verbosity){ ssh_session session; int auth=0; session=ssh_new(); if(session==NULL) return(NULL); if(user!=NULL) { if(ssh_options_set(session,SSH_OPTIONS_USER,user)<0) { ssh_free(session); return NULL; } } if(ssh_options_set(session,SSH_OPTIONS_HOST,host)<0) { ssh_free(session); return(NULL); } ssh_options_set(session,SSH_OPTIONS_LOG_VERBOSITY,&verbosity); if(ssh_connect(session)) { prterr("Connection failed : %s/n",ssh_get_error(session)); ssh_disconnect(session); ssh_free(session); return(NULL); } if(verify_knownhost(session)<0) { ssh_disconnect(session); ssh_free(session); return(NULL); } auth=authenticate_console(session); if(auth==SSH_AUTH_SUCCESS) { return(session); } else if(auth==SSH_AUTH_DENIED) { prterr("Error: Authentication failed."); } else { prterr("Error while authenticating : %s/n",ssh_get_error(session)); } ssh_disconnect(session); ssh_free(session); return(NULL);}
开发者ID:DTidd,项目名称:OpenRDAAPI,代码行数:49,
示例16: testint test(){ ssh_session my_ssh_session; int rc; // Open session and set options my_ssh_session = ssh_new(); if (my_ssh_session == NULL) exit(-1); ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost"); // Connect to server rc = ssh_connect(my_ssh_session); if (rc != SSH_OK) { fprintf(stderr, "Error connecting to localhost: %s/n", ssh_get_error(my_ssh_session)); ssh_free(my_ssh_session); exit(-1); } // Verify the server's identity // For the source code of verify_knowhost(), check previous example// if (verify_knownhost(my_ssh_session) < 0)// {// ssh_disconnect(my_ssh_session);// ssh_free(my_ssh_session);// exit(-1);// } // Authenticate ourselves QString password("whcrosedu"); rc = ssh_userauth_password(my_ssh_session, NULL, password.toLatin1()); if (rc != SSH_AUTH_SUCCESS) { fprintf(stderr, "Error authenticating with password: %s/n", ssh_get_error(my_ssh_session)); ssh_disconnect(my_ssh_session); ssh_free(my_ssh_session); exit(-1); } qDebug()<<"evrika"; show_remote_processes(my_ssh_session); ssh_disconnect(my_ssh_session); ssh_free(my_ssh_session);}
开发者ID:CorneliuAndrei,项目名称:WHC-IDE,代码行数:48,
示例17: mainint main(int argc, char **argv){ ssh_session_t *session = NULL; session = ssh_new(); ssh_callbacks_init(&cb); ssh_set_callbacks(session,&cb); if(ssh_options_getopt(session, &argc, argv)) { fprintf(stderr, "error parsing command line :%s/n", ssh_get_error(session)); usage(); } opts(argc,argv); signal(SIGTERM, do_exit); client(session); ssh_disconnect(session); ssh_free(session); ssh_finalize(); return 0;}
开发者ID:caidongyun,项目名称:ssh-proxy,代码行数:27,
示例18: channel_rcv_change_windowstatic void channel_rcv_change_window(SSH_SESSION *session) { CHANNEL *channel; u32 bytes; int rc; enter_function(); channel = channel_from_msg(session); if (channel == NULL) { ssh_log(session, SSH_LOG_FUNCTIONS, ssh_get_error(session)); } rc = buffer_get_u32(session->in_buffer, &bytes); if (channel == NULL || rc != sizeof(u32)) { ssh_log(session, SSH_LOG_PACKET, "Error getting a window adjust message: invalid packet"); leave_function(); return; } bytes = ntohl(bytes); ssh_log(session, SSH_LOG_PROTOCOL, "Adding %d bytes to channel (%d:%d) (from %d bytes)", bytes, channel->local_channel, channel->remote_channel, channel->remote_window); channel->remote_window += bytes; leave_function();}
开发者ID:BackupTheBerlios,项目名称:libssh-svn,代码行数:32,
示例19: ssh_channel_read_nonblockingvoid clSSH::OnCheckRemoteOutut(wxTimerEvent& event){ if(!m_channel) return; char buffer[1024]; int nbytes = ssh_channel_read_nonblocking(m_channel, buffer, sizeof(buffer), 0); if(nbytes > 0) { wxString strOutput = wxString::FromUTF8((const char*)buffer, nbytes); clCommandEvent sshEvent(wxEVT_SSH_COMMAND_OUTPUT); sshEvent.SetString(strOutput); m_owner->AddPendingEvent(sshEvent); } else if(nbytes == SSH_ERROR) { m_timer->Stop(); DoCloseChannel(); clCommandEvent sshEvent(wxEVT_SSH_COMMAND_ERROR); sshEvent.SetString(ssh_get_error(m_session)); m_owner->AddPendingEvent(sshEvent); } else { // nbytes == 0 if(ssh_channel_is_eof(m_channel)) { m_timer->Stop(); DoCloseChannel(); // EOF was sent, nothing more to read clCommandEvent sshEvent(wxEVT_SSH_COMMAND_COMPLETED); m_owner->AddPendingEvent(sshEvent); } else { // Nothing to read, no error } }}
开发者ID:eranif,项目名称:codelite,代码行数:32,
示例20: doCopyint doCopy(int argc, char **argv){ struct location *dest, *src; int i; int r; if(opts(argc,argv)<0) return EXIT_FAILURE; dest=parse_location(destination); if(open_location(dest,WRITE)<0) return EXIT_FAILURE; for(i=0;i<nsources;++i){ src=parse_location(sources[i]); if(open_location(src,READ)<0){ return EXIT_FAILURE; } if(do_copy(src,dest,0) < 0){ break; } } if(dest->is_ssh){ r=ssh_scp_close(dest->scp); if(r == SSH_ERROR){ fprintf(stderr,"Error closing scp: %s/n",ssh_get_error(dest->session)); ssh_scp_free(dest->scp); dest->scp=NULL; return -1; } } else { fclose(dest->file); dest->file=NULL; } ssh_disconnect(dest->session); ssh_finalize(); return 0;}
开发者ID:CorneliuAndrei,项目名称:WHC-IDE,代码行数:34,
示例21: on_pty_eventstatic void on_pty_event(struct tmate_session *session){ ssize_t len, written; char buf[4096]; for (;;) { len = read(session->pty, buf, sizeof(buf)); if (len < 0) { if (errno == EAGAIN) return; tmate_fatal("pty read error"); } if (len == 0) tmate_fatal("pty reached EOF"); written = ssh_channel_write(session->ssh_client.channel, buf, len); if (written < 0) tmate_fatal("Error writing to channel: %s", ssh_get_error(session->ssh_client.session)); if (len != written) tmate_fatal("Cannot write %d bytes, wrote %d", (int)len, (int)written); }}
开发者ID:abergmann,项目名称:tmate-slave,代码行数:25,
示例22: verify_knownhostint verify_knownhost(ssh_session session){ char *hexa; int state; char buf[10]; unsigned char *hash = NULL; int hlen; state=ssh_is_server_known(session); hlen = ssh_get_pubkey_hash(session, &hash); if (hlen < 0) { return -1; } switch(state){ case SSH_SERVER_KNOWN_OK: break; /* ok */ case SSH_SERVER_KNOWN_CHANGED: fprintf(stderr,"Host key for server changed : server's one is now :/n"); ssh_print_hexa("Public key hash",hash, hlen); free(hash); fprintf(stderr,"For security reason, connection will be stopped/n"); return -1; case SSH_SERVER_FOUND_OTHER: fprintf(stderr,"The host key for this server was not found but an other type of key exists./n"); fprintf(stderr,"An attacker might change the default server key to confuse your client" "into thinking the key does not exist/n" "We advise you to rerun the client with -d or -r for more safety./n"); return -1; case SSH_SERVER_FILE_NOT_FOUND: fprintf(stderr,"Could not find known host file. If you accept the host key here,/n"); fprintf(stderr,"the file will be automatically created./n"); /* fallback to SSH_SERVER_NOT_KNOWN behavior */ case SSH_SERVER_NOT_KNOWN: hexa = ssh_get_hexa(hash, hlen); fprintf(stderr,"The server is unknown. Do you trust the host key ?/n"); fprintf(stderr, "Public key hash: %s/n", hexa); free(hexa); fgets(buf,sizeof(buf),stdin); if(strncasecmp(buf,"yes",3)!=0){ return -1; } fprintf(stderr,"This new key will be written on disk for further usage. do you agree ?/n"); fgets(buf,sizeof(buf),stdin); if(strncasecmp(buf,"yes",3)==0){ if (ssh_write_knownhost(session) < 0) { free(hash); fprintf(stderr, "error %s/n", strerror(errno)); return -1; } } break; case SSH_SERVER_ERROR: free(hash); fprintf(stderr,"%s",ssh_get_error(session)); return -1; } free(hash); return 0;}
开发者ID:CUEBoxer,项目名称:OpenStudio,代码行数:60,
示例23: mainint main(int argc, char **argv){ ssh_session session; session = ssh_new(); if(ssh_options_getopt(session, &argc, argv)) { fprintf(stderr, "error parsing command line :%s/n", ssh_get_error(session)); usage(); } opts(argc,argv);#ifdef WITH_PCAP set_pcap(session);#endif client(session); ssh_disconnect(session); ssh_free(session);#ifdef WITH_PCAP cleanup_pcap();#endif ssh_finalize(); return 0;}
开发者ID:R4wizard,项目名称:node-libssh,代码行数:26,
示例24: clientstatic int client(ssh_session session){ int auth=0; char *banner; int state; if (ssh_options_set(session, SSH_OPTIONS_HOST ,host) < 0) return -1; ssh_options_parse_config(session, NULL); if(ssh_connect(session)){ fprintf(stderr,"Connection failed : %s/n",ssh_get_error(session)); return -1; } state=verify_knownhost(session); if (state != 0) return -1; ssh_userauth_none(session, NULL); banner=ssh_get_issue_banner(session); if(banner){ printf("%s/n",banner); free(banner); } auth=authenticate_console(session); if(auth != SSH_AUTH_SUCCESS){ return -1; } forwarding(session); return 0;}
开发者ID:R4wizard,项目名称:node-libssh,代码行数:29,
示例25: scp_errorstatic void scp_error(lua_State *L,struct scp_ud *scpud){ ssh_session session=scp_close(scpud); if(session==NULL){ luaL_error(L, "stp %p already closed", scpud); } luaL_error(L,ssh_get_error(session));}
开发者ID:wangyi0226,项目名称:luassh,代码行数:7,
示例26: benchmarks_ssh_latency/** @internal * @brief Calculates the RTT of the host with SSH channel operations, and * returns the average of the calculated RTT. * @param[in] session active SSH session to test. * @param[out] average average RTT in milliseconds. * @returns 0 on success, -1 if there is an error. */int benchmarks_ssh_latency(ssh_session session, float *average){ float times[3]; struct timestamp_struct ts; int i; ssh_channel channel; channel=ssh_channel_new(session); if(channel==NULL) goto error; if(ssh_channel_open_session(channel)==SSH_ERROR) goto error; for(i=0;i<3;++i){ timestamp_init(&ts); if(ssh_channel_request_env(channel,"TEST","test")==SSH_ERROR && ssh_get_error_code(session)==SSH_FATAL) goto error; times[i]=elapsed_time(&ts); } ssh_channel_close(channel); ssh_channel_free(channel); channel=NULL; printf("Times : %f ms ; %f ms ; %f ms/n", times[0], times[1], times[2]); *average=(times[0]+times[1]+times[2])/3; return 0;error: fprintf(stderr,"Error calculating SSH latency : %s/n",ssh_get_error(session)); if(channel) ssh_channel_free(channel); return -1;}
开发者ID:FuckingCoder,项目名称:libssh,代码行数:37,
示例27: ssh_scp_push_directory/** * @brief Create a directory in a scp in sink mode. * * @param[in] scp The scp handle. * * @param[in] dirname The name of the directory being created. * * @param[in] mode The UNIX permissions for the new directory, e.g. 0755. * * @returns SSH_OK if the directory has been created, SSH_ERROR if * an error occured. * * @see ssh_scp_leave_directory() */int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode){ char buffer[1024]; int r; uint8_t code; char *dir; char *perms; if(scp==NULL) return SSH_ERROR; if(scp->state != SSH_SCP_WRITE_INITED){ ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_push_directory called under invalid state"); return SSH_ERROR; } dir=ssh_basename(dirname); perms=ssh_scp_string_mode(mode); snprintf(buffer, sizeof(buffer), "D%s 0 %s/n", perms, dir); SAFE_FREE(dir); SAFE_FREE(perms); r=ssh_channel_write(scp->channel,buffer,strlen(buffer)); if(r==SSH_ERROR){ scp->state=SSH_SCP_ERROR; return SSH_ERROR; } r=ssh_channel_read(scp->channel,&code,1,0); if(r<=0){ ssh_set_error(scp->session,SSH_FATAL, "Error reading status code: %s",ssh_get_error(scp->session)); scp->state=SSH_SCP_ERROR; return SSH_ERROR; } if(code != 0){ ssh_set_error(scp->session,SSH_FATAL, "scp status code %ud not valid", code); scp->state=SSH_SCP_ERROR; return SSH_ERROR; } return SSH_OK;}
开发者ID:Paxxi,项目名称:libssh,代码行数:49,
示例28: ssh_scp_leave_directory/** * @brief Leave a directory. * * @returns SSH_OK if the directory has been left,SSH_ERROR if an * error occured. * * @see ssh_scp_push_directory() */ int ssh_scp_leave_directory(ssh_scp scp){ char buffer[]="E/n"; int r; uint8_t code; if(scp==NULL) return SSH_ERROR; if(scp->state != SSH_SCP_WRITE_INITED){ ssh_set_error(scp->session,SSH_FATAL,"ssh_scp_leave_directory called under invalid state"); return SSH_ERROR; } r=ssh_channel_write(scp->channel,buffer,strlen(buffer)); if(r==SSH_ERROR){ scp->state=SSH_SCP_ERROR; return SSH_ERROR; } r=ssh_channel_read(scp->channel,&code,1,0); if(r<=0){ ssh_set_error(scp->session,SSH_FATAL, "Error reading status code: %s",ssh_get_error(scp->session)); scp->state=SSH_SCP_ERROR; return SSH_ERROR; } if(code != 0){ ssh_set_error(scp->session,SSH_FATAL, "scp status code %ud not valid", code); scp->state=SSH_SCP_ERROR; return SSH_ERROR; } return SSH_OK;}
开发者ID:Paxxi,项目名称:libssh,代码行数:36,
示例29: prepare_sshstatic ssh_bind prepare_ssh(const char *keys_dir, int port){ ssh_bind bind; char buffer[PATH_MAX]; int verbosity = SSH_LOG_NOLOG; ssh_set_log_callback(ssh_log_function); bind = ssh_bind_new(); if (!bind) tmate_fatal("Cannot initialize ssh"); ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BINDPORT, &port); ssh_bind_options_set(bind, SSH_BIND_OPTIONS_BANNER, TMATE_SSH_BANNER); ssh_bind_options_set(bind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &verbosity); sprintf(buffer, "%s/ssh_host_rsa_key", keys_dir); ssh_bind_options_set(bind, SSH_BIND_OPTIONS_RSAKEY, buffer); sprintf(buffer, "%s/ssh_host_ecdsa_key", keys_dir); ssh_bind_options_set(bind, SSH_BIND_OPTIONS_ECDSAKEY, buffer); if (ssh_bind_listen(bind) < 0) tmate_fatal("Error listening to socket: %s/n", ssh_get_error(bind)); tmate_notice("Accepting connections on %d", port); return bind;}
开发者ID:abergmann,项目名称:tmate-slave,代码行数:29,
注:本文中的ssh_get_error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ ssh_log函数代码示例 C++ ssh_error函数代码示例 |