I am using a rails webapp and trying to send an xml file to a sftp server, using the following script:
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
Nevertheless, I am always get an error "Errno::ENOTTY ... Inappropriate ioctl for device"
. Any help how to fix this error?
An IOCTL is a Device Input and Output Control meaning the error comes from a poorly formed or misconfigured command being sent to the server.
It could be the PTY issue described in a comment as the server does not have a terminal output and SFTP is attempting to display the progress bar.
Alternatively, it could be a result of a poorly formed command being sent to the server as the output of measurements_xml_file_path( meas ).to_s
is unknown and possibly incorrect. SFTP takes two arguments, one for the input file on the host and one for the output file on the server.
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")