Errno::ENOTTY 尝试将文件发送到 SFTP 时设备的 ioctl 不合适

moh*_*814 7 ssh sftp ioctl ruby-on-rails

我正在使用 Rails Web 应用程序并尝试使用以下脚本将 xml 文件发送到 sftp 服务器:

Net::SSH.start(SFTP_HOST, sftp_user, {:port => SFTP_PORT, :password => sftp_password}) do |ssh|
ssh.sftp.connect do |sftp|
  sftp.upload!( measurements_xml_file_path( meas ).to_s ) do |event, uploader, *args|
    case even
    when :open
      puts "Starting upload"

    when :finish
      puts "Finished upload"
      return true
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

尽管如此,我总是收到错误"Errno::ENOTTY ... Inappropriate ioctl for device"。有帮助如何修复此错误吗?

ajg*_*nds 1

IOCTL 是设备输入和输出控制,这意味着错误来自发送到服务器的格式不正确或配置错误的命令。

这可能是评论中描述的 PTY 问题,因为服务器没有终端输出,并且 SFTP 正在尝试显示进度条。

或者,这可能是由于发送到服务器的格式不正确的命令造成的,因为 的输出measurements_xml_file_path( meas ).to_s未知并且可能不正确。SFTP 有两个参数,一个用于主机上的输入文件,一个用于服务器上的输出文件。

类 Net::SFTP

To upload a single file to the remote server, simply specify both the local and remote paths:

uploader = sftp.upload("/path/to/local.txt", "/path/to/remote.txt")
Run Code Online (Sandbox Code Playgroud)