|
| 1 | +/** |
| 2 | + * @author Jonathan Cardoso Machado |
| 3 | + * @license MIT |
| 4 | + * @copyright 2016, Jonathan Cardoso Machado |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 10 | + * of the Software, and to permit persons to whom the Software is furnished to do |
| 11 | + * so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 18 | + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 19 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 20 | + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 21 | + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | + */ |
| 23 | + |
| 24 | +/** |
| 25 | + * Example showing how one could connect to one ssh server using sftp |
| 26 | + */ |
| 27 | +var Easy = require( '../lib/Easy' ), |
| 28 | + Curl = require( '../lib/Curl' ), |
| 29 | + host = process.argv[2] || 'sftp://user:pass@host', |
| 30 | + ch, ret; |
| 31 | + |
| 32 | +ch = new Easy(); |
| 33 | + |
| 34 | +ch.setOpt( Curl.option.URL, host ); |
| 35 | +ch.setOpt( Curl.option.VERBOSE, true ); |
| 36 | +ch.setOpt( Curl.option.SSH_AUTH_TYPES, Curl.ssh_auth.PASSWORD ); |
| 37 | + |
| 38 | +ch.onData = function( buf, size, nmemb ) { |
| 39 | + |
| 40 | + console.log( buf.toString( 'utf8' ) ); |
| 41 | + |
| 42 | + return size * nmemb; |
| 43 | +}; |
| 44 | + |
| 45 | +ret = ch.perform(); |
| 46 | + |
| 47 | +ch.close(); |
| 48 | + |
| 49 | +console.log( ret, ret == Curl.code.CURLE_OK, Easy.strError( ret ) ); |
0 commit comments