With Net::SFTP::Foreign's OpenSSH backend, proxy routing can be expressed as an SSH option. The module's documented more parameter accepts an array of command arguments:

use Net::SFTP::Foreign;

my $sftp = Net::SFTP::Foreign->new(
    'files.example.net',
    user => 'operator',
    more => [
        '-o',
        'ProxyCommand=nc -X 5 -x proxy.example.net:1080 %h %p',
    ],
);

die $sftp->error if $sftp->error;

This assumes an existing OpenBSD-compatible nc helper. OpenSSH runs it locally to establish a SOCKS5 connection to the SFTP destination. The placeholders supply SSH's selected host and port. To reach a public SFTP server through an allowed public intermediary, select a no-account endpoint from the SOCKS5 proxy list for the helper; it must permit that SSH destination and port.

The argument boundary matters: -o is one argument, and the entire ProxyCommand assignment is the next. Net::SFTP::Foreign's more parameter does not treat an arbitrary string containing several SSH arguments as an array automatically.

An application can also keep the ProxyCommand in its ordinary SSH Host configuration and pass that host alias to Net::SFTP::Foreign. Use the OpenSSH backend's configuration in either form; a different backend such as Plink has its own option syntax.

Artiglyn mynjee