SFTP Create an SFTP object. Syntax: H = SFTP(HOST) H = SFTP(HOST, USERNAME) H = SFTP(HOST, USERNAME, PASSWORD) Description: H = SFTP(HOST, USERNAME, PASSWORD) returns an SFTP object. If USERNAME is not specified, the default user for that host will be used. If PASSWORD is not specified, public key authentication will be used. Examples: h = sftp(host) h = sftp(host, username) h = sftp(host, username, password) See also: CLOSE CD DIR MGET MPUT RENAME DELETE MKDIR RMDIR Authors: Joan Pau Beltran <joanpau.beltran@socib.cat>
0001 function h = sftp(host, username, password) 0002 %SFTP Create an SFTP object. 0003 % 0004 % Syntax: 0005 % H = SFTP(HOST) 0006 % H = SFTP(HOST, USERNAME) 0007 % H = SFTP(HOST, USERNAME, PASSWORD) 0008 % 0009 % Description: 0010 % H = SFTP(HOST, USERNAME, PASSWORD) returns an SFTP object. 0011 % If USERNAME is not specified, the default user for that host will be used. 0012 % If PASSWORD is not specified, public key authentication will be used. 0013 % 0014 % Examples: 0015 % h = sftp(host) 0016 % h = sftp(host, username) 0017 % h = sftp(host, username, password) 0018 % 0019 % See also: 0020 % CLOSE 0021 % CD 0022 % DIR 0023 % MGET 0024 % MPUT 0025 % RENAME 0026 % DELETE 0027 % MKDIR 0028 % RMDIR 0029 % 0030 % Authors: 0031 % Joan Pau Beltran <joanpau.beltran@socib.cat> 0032 0033 % Copyright (C) 2014-2016 0034 % ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears 0035 % <http://www.socib.es> 0036 % 0037 % This program is free software: you can redistribute it and/or modify 0038 % it under the terms of the GNU General Public License as published by 0039 % the Free Software Foundation, either version 3 of the License, or 0040 % (at your option) any later version. 0041 % 0042 % This program is distributed in the hope that it will be useful, 0043 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0044 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0045 % GNU General Public License for more details. 0046 % 0047 % You should have received a copy of the GNU General Public License 0048 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0049 0050 error(nargchk(0, 3, nargin, 'struct')); 0051 0052 if (nargin == 1) && isa(host, 'sftp') 0053 % Short circuit copy constructor. 0054 h = host; 0055 else 0056 switch nargin 0057 case 0 0058 host = []; 0059 username = []; 0060 password = []; 0061 case 1 0062 username = []; 0063 password = []; 0064 case 2 0065 password = []; 0066 end 0067 colon = find(host==':'); 0068 if isempty(colon) 0069 h.host = host; 0070 h.port = []; 0071 else 0072 h.host = host(1:colon-1); 0073 h.port = str2double(host(colon+1:end)); 0074 end 0075 h.username = username; 0076 h.password = password; 0077 h.sftp_handle = mexsftp('create', h.host, h.port, h.username, h.password); 0078 h.cleanup = onCleanup(@()(mexsftp('delete', h.sftp_handle))); 0079 h = class(h, 'sftp'); 0080 end 0081 0082 end