Can't connect SFTP(AWS EC2) with QuotaGuard Static IP

186 views Asked by At

I am using QuotaGuard Static Addon on Heroku to access the SFTP server(AWS EC2) which has whitelisted IP.

I have tried to connect with a private key file. This is my code.

def connect
  puts "started"
  Net::SSH.start(ENV["HOST"], ENV["USER"],
    {
      :key_data => [ ENV["FTP_KEY"] ],
      :keys => [],
      :keys_only => true,
      :verbose => :debug,
      :proxy => proxy
    }
  ) do |ssh|
    ssh.sftp.connect do |sftp|
      sftp.dir.foreach("/") do |entry|
          puts entry.longname
      end
    end
  end
  puts "done"
end

def quotaguard
  URI(ENV["QUOTAGUARDSTATIC_URL"])
end

def proxy
  Net::SSH::Proxy::HTTP.new(quotaguard.host,quotaguard.port, :user => quotaguard.user,:password=> quotaguard.password)
end

But it is failed to connect with this error.

WARN: Net::SSH::Proxy::ConnectError: {:version=>"HTTP/1.1", :code=>502, :reason=>"Bad Gateway", :headers=>{}, :body=>nil}

HOST, USER, FTP_KEY, and QUOTAGUARDSTATIC_URL are Heroku Env variables.

My thought:

I think to connect AWS EC2 using the proxy, maybe some settings need to be configured to allow proxy on AWS EC2.

But not sure.

1

There are 1 answers

0
Remy Wang On

There was the wrong Security Group on AWS EC2. I updated and I can connect now.