Why am I getting this error from net-scp?


#1

Folks,

So, I’m doing some compliance work for a customer (not PCI, but similar), and one thing we decided was to use scp to upload and download large files from a central fileserver. This way we don’t have to worry about opening any more holes in firewalls (because ssh already has to be open), no additional Pandoras Boxes, etc…

The download works fine. But when I’m trying to upload the results of the scan, it bombs out. The weird thing is that the code uses Mixlib::ShellOut to go find the file in question just a few lines above, but then Net:Scp craps out.

A slice of logs showing the error message is at http://pastebin.com/YXPu4TKS.

I haven’t done the Windows side of the code yet, but the Linux part of the code for this section looks like this:

if platform_family?(“rhel”)
ruby_block ‘find-and-upload-ciscat-results’ do
block do
require 'mixlib/shellout’
require 'net/scp’
cmd = Mixlib::ShellOut.new(“find #{resdir} -name ‘*.xml’ | sort | tail -1”)
cmd.run_command
cmd.error!
source = cmd.stdout
Chef::Log.debug(“Uploading source file #{source} to #{user}@#{host}:#{target}”)
Net::SCP.upload!(host, user, source, target, :ssh => { :password => pass })
end
end

elsif platform_family?(“windows”)

end

Am I doing something incredibly stupid here?


Brad Knowles brad@shub-internet.org
LinkedIn Profile: http://tinyurl.com/y8kpxu


#2

Hi,

  source    = cmd.stdout

My guess is your output has a newline attached to it. Since newlines
are valid characters in filenames, there is no reason for this to
raise an error before the file can’t be found. Try:

source = cmd.stdout.chomp

Cheers,

Steven

On Wed, Nov 26, 2014 at 3:11 AM, Brad Knowles brad@shub-internet.org wrote:

Folks,

So, I’m doing some compliance work for a customer (not PCI, but similar), and one thing we decided was to use scp to upload and download large files from a central fileserver. This way we don’t have to worry about opening any more holes in firewalls (because ssh already has to be open), no additional Pandoras Boxes, etc…

The download works fine. But when I’m trying to upload the results of the scan, it bombs out. The weird thing is that the code uses Mixlib::ShellOut to go find the file in question just a few lines above, but then Net:Scp craps out.

A slice of logs showing the error message is at http://pastebin.com/YXPu4TKS.

I haven’t done the Windows side of the code yet, but the Linux part of the code for this section looks like this:

if platform_family?(“rhel”)
ruby_block ‘find-and-upload-ciscat-results’ do
block do
require 'mixlib/shellout’
require 'net/scp’
cmd = Mixlib::ShellOut.new(“find #{resdir} -name ‘*.xml’ | sort | tail -1”)
cmd.run_command
cmd.error!
source = cmd.stdout
Chef::Log.debug(“Uploading source file #{source} to #{user}@#{host}:#{target}”)
Net::SCP.upload!(host, user, source, target, :ssh => { :password => pass })
end
end

elsif platform_family?(“windows”)

end

Am I doing something incredibly stupid here?


Brad Knowles brad@shub-internet.org
LinkedIn Profile: http://tinyurl.com/y8kpxu


#3

Hi,

As a quick followup, if you wanted to avoid shelling out, you could do
something like:

Dir.glob(’/full/path/to/dir/*.xml’).sort.last

Cheers,

Steven

On Wed, Nov 26, 2014 at 12:35 PM, Steven Danna steve@opscode.com wrote:

Hi,

  source    = cmd.stdout

My guess is your output has a newline attached to it. Since newlines
are valid characters in filenames, there is no reason for this to
raise an error before the file can’t be found. Try:

source = cmd.stdout.chomp

Cheers,

Steven

On Wed, Nov 26, 2014 at 3:11 AM, Brad Knowles brad@shub-internet.org wrote:

Folks,

So, I’m doing some compliance work for a customer (not PCI, but similar), and one thing we decided was to use scp to upload and download large files from a central fileserver. This way we don’t have to worry about opening any more holes in firewalls (because ssh already has to be open), no additional Pandoras Boxes, etc…

The download works fine. But when I’m trying to upload the results of the scan, it bombs out. The weird thing is that the code uses Mixlib::ShellOut to go find the file in question just a few lines above, but then Net:Scp craps out.

A slice of logs showing the error message is at http://pastebin.com/YXPu4TKS.

I haven’t done the Windows side of the code yet, but the Linux part of the code for this section looks like this:

if platform_family?(“rhel”)
ruby_block ‘find-and-upload-ciscat-results’ do
block do
require 'mixlib/shellout’
require 'net/scp’
cmd = Mixlib::ShellOut.new(“find #{resdir} -name ‘*.xml’ | sort | tail -1”)
cmd.run_command
cmd.error!
source = cmd.stdout
Chef::Log.debug(“Uploading source file #{source} to #{user}@#{host}:#{target}”)
Net::SCP.upload!(host, user, source, target, :ssh => { :password => pass })
end
end

elsif platform_family?(“windows”)

end

Am I doing something incredibly stupid here?


Brad Knowles brad@shub-internet.org
LinkedIn Profile: http://tinyurl.com/y8kpxu


#4

On Nov 26, 2014, at 6:35 AM, Steven Danna steve@opscode.com wrote:

 source    = cmd.stdout

My guess is your output has a newline attached to it. Since newlines
are valid characters in filenames, there is no reason for this to
raise an error before the file can’t be found. Try:

source = cmd.stdout.chomp

Weird. Because there’s no newline showing up in any of the log messages. But I can give this a try.

Thanks!


Brad Knowles brad@shub-internet.org
LinkedIn Profile: http://tinyurl.com/y8kpxu


#5

On Nov 26, 2014, at 6:42 AM, Steven Danna steve@opscode.com wrote:

As a quick followup, if you wanted to avoid shelling out, you could do
something like:

Dir.glob(’/full/path/to/dir/*.xml’).sort.last

Awesome! Yes, I would much prefer a native Ruby solution to this issue, rather than shelling out. I just wish I spoke Ruby. :wink:

Thanks again!


Brad Knowles brad@shub-internet.org
LinkedIn Profile: http://tinyurl.com/y8kpxu