%sFtpConnect %connects Matlab to a remote server % %in------------------------------------------------------------------------ % hostName: address of host machine % userName: THEW username % password: THEW password % %out----------------------------------------------------------------------- % channel: a Java ChannelShell object of the connection % sftpcl: a Java SFTPv3Client object (instance of sftp client class) %########################################################################## function [ sftpcl, channel ] = sFtpConnect(userName, hostName, password) import ch.ethz.ssh2.SFTPv3Client; import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.Session; import ch.ethz.ssh2.SFTPv3FileHandle; if(nargin ~= 3) error('Error: sFtpConnect requires 3 input arguments...'); end if(~ischar(userName) || ~ischar(hostName) || ~ischar(password)) error... (['Error: sFtpConnect requires all input ',... 'arguments to be strings...']); end %Set up the connection with the remote server try channel = Connection(hostName); channel.connect(); catch error(['Error: sFtpConnect could not connect to the'... ' remote machine %s ...'],hostName); end % % Check the authentication for login... % isAuthenticated = channel.authenticateWithPassword(userName,password); if(~isAuthenticated) error... (['Error: sFtpConnect could not authenticate the',... ' SSH connection...']); end %Open session sftpcl = SFTPv3Client(channel); end