Clear Filters
Clear Filters

SFTP through firewall fails to use proxy

24 views (last 30 days)
Jeff Mandel
Jeff Mandel on 15 Feb 2024
Answered: Siraj on 19 Feb 2024
I work in a building that has an overly-restrictive firewall. On my Mac, I have ~/.ssh/config, I handle this with:
ProxyCommand /opt/local/bin/proxytunnel -E -p -d
If I sftp from the command line, I see if correctly reads the config file and connects through proxytunnel. Matlab's sftp seems to ignore ~/.ssh/config. Digging deeper, I see sftp purports to support an HTTP proxy. In my Apache site for, I have:
AllowConnect 22
This works fine as a SOCKS proxy (Apple Mail, for instance), but does not work either setting in MATLAB Web Preferences or in Mac Network proxy settings, or using the SOCKS proxy locally ( I'd prefer not to resort to a Java solution unless this can't be done with pure MATLAB.

Answers (1)

Siraj on 19 Feb 2024
It is my understanding that you’re trying to use "sftp" with proxy server settings to connect to a server and access its files but are running into some trouble. You've mentioned that you can connect to the server using sftp from the command line without any issues, yet when you try to use MATLAB's "sftp" function, you encounter problems.
The SFTP object created by the “sftp” function does not support proxy server settings, which is why it seems like your config file is being ignored. You can verify this limitation by checking the documentation provided by MathWorks at the following link:
As an alternative, you can try connecting to the server using SSH keys. In the "sftp" function, you can specify the paths to your public and private key files with the "PublicKeyFile" and "PrivateKeyFile" arguments. This method could provide a way for authentication. The default location of these key files is dependent on your operating system. Here's how you might use these arguments in your code:
s = sftp("", "jsmith", "PublicKeyFile","/Users/abc/sshKeys/", "PrivateKeyFile","/Users/abc/sshKeys/keys");
You can find more information in the MATLAB "sftp" function documentation:
Hope this helps.





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!