File Exchange Pick of the Week

Our best user submissions

Secure FTP (SSH/SFTP/SCP)

Jiro's pick this week is "SSH/SFTP/SCP For Matlab (v2)" by David Freedman.

Recently, we changed our internal server for our blogs, and now we are using Secure FTP to upload images and files. When we were using the old system (FTP), many of us used MATLAB's ftp or Passive Mode FTP (Picked by Sean) to automate the file transfer.

With the new system, I needed an SFTP-equivalence to the ftp function. Of course, I looked to the File Exchange! David's entry is a well-written package that interfaces to an open-source Ganymed SSH-2 Java library. The entry comes with a version of the library, but it can also be set up to download a version from the web. The setup is very simple and seamless. What I also like about this entry is that David provides simple interface commands to SSH/SCP/SFT, as well as advanced interface functions.

The simple interface works like this:

scp_simple_put('sftp.thishost.com','username','password',...
    {'file1.m','file2.txt'},'/var/host/user/',pwd)

With a single command, you specify the server, the files, and the location you want to upload to.

If you want more control, the advanced interface works like this:

% Create a connection
s_conn = ssh2_config('sftp.thishost.com','username','password');

% Run a command, such as "create a folder"
ssh2_command(s_conn,'mkdir /var/host/user/temp');

% Copy files from local to remote
scp_put(s_conn,{'file1.m','file2.txt'},'/var/host/user/temp',pwd);

% Close the connection
ssh2_close(s_conn);

David has documented the functions well and also has included examples for you to try. Thanks, David, for making this transition from FTP to SFTP so simple!

Comments

Give this a try, and let us know what you think here or leave a comment for David.




Published with MATLAB® R2016a

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.