我正在开发一个集成,需要我的 Rails 4 应用程序每天将 CSV 推送到 SFTP 服务器。该应用程序最终将在 Heroku 上运行。
我正在使用“net-sftp”gem。
通过 FTP 客户端 (FileZilla) 移动文件是可行的。
这是我尝试使用的非常简单的类:
require 'net/ssh'
require 'net/sftp'
class SFTP
def initialize(org)
case org
when 'client'
@host = ENV['HOST']
@username = ENV['USERNAME']
@password = ENV['PASSWORD']
@port = ENV['PORT']
end
end
def send(local_path)
Net::SFTP.start(@host, @username , { password: @password, port: @port } ) do |sftp|
sftp.upload!(local_path, "/files")
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
require 'net/ssh'
require 'net/sftp'
class SFTP
def initialize(org)
case org
when 'client'
@host = ENV['HOST']
@username = …
Run Code Online (Sandbox Code Playgroud)