Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

Tuesday, 9 December 2008

sftp from behind firewall via HTTP proxy in Ruby

Same as the previous Post using ruby:
require 'rubygems'
require 'net/ssh'
require 'net/sftp'
require 'net/ssh/proxy/http'

base_dir = "/some_base_directory"

proxy_host = 'IP_or_FQDN_of_your_proxy'
proxy_port = port_of_your_proxy

proxy = Net::SSH::Proxy::HTTP.new(proxy_host,proxy_port)

Net::SSH.start('destination_IP_or_FQDN','username',
{:proxy => proxy,
:password => 'password'}) do |ssh|

ssh.sftp.connect do |sftp|
# do something
end
end

ssh sftp from behind firewall via HTTP proxy

If you work in corporate network that is behind firewall.

if you try this:
chris@emeadb:~$ sftp username@xx.xx.xx.xx
Connecting to xx.xx.xx.xx...
ssh: connect to host xx.xx.xx.xx port 22: No route to host
Couldn't read packet: Connection reset by peer

With help comes connect-proxy
Install it with (in debian like systems):
sudo apt-get install connect-proxy

then configure it:
vi ~/.ssh/config

adjust to your needs the content:
Host *
ProxyCommand connect-proxy -H <IP or FQDN of your proxy>:<port> %h %p

enjoy:
chris@emeadb:~$ sftp username@xx.xx.xx.xx
Connecting to xx.xx.xx.xx...
Secure SFTP Serverusername@xx.xx.xx.xx's password: