Вопрос

I'm trying to use Carrierwave to upload files, and then after the upload is complete, use the ruby-nmap XML parser to populate some fields.

I set a sleep timer to 8 to just make sure the files are getting uploaded. I've set this as much as 20. I can see them getting uploaded and are in the correct directory. However, ruby-nmap says it cannot find the file as if it doesn't exist.

I generated a simple scaffold and I'm manipulating the "def create" portion.

controller code:

def create
@nmapfile = Nmapfile.new(nmapfile_params)
@nmapfile.nmapfilerecords = 0
@nmapfile.save
sleep 8
Nmap::XML.new(@nmapfile.nmapxml.to_s) do |xml|
    xml.each_host do |host|
      if "#{host.status}" == "down"            
      else
        @nmapfile.nmapfilerecords += 1
      end
    end
end

respond_to do |format|
  if @nmapfile.save
    format.html { redirect_to @nmapfile, notice: 'nmap file was successfully created.' }
    format.json { render action: 'show', status: :created, location: @nmapfile }
  else
    format.html { render action: 'new' }
    format.json { render json: @nmapfile.errors, status: :unprocessable_entity }
  end
end
end

The error I'm getting is: Errno::ENOENT in NmapfilesController#create (No such file or directory - /uploads/nmapfile/nmapxml/21/scan.xml)

Yet, scan.xml DOES exist in that directory.

I ran this just as a simple ruby script at it works. The output shows 11 on the console screen. So there isn't an issue with the file. It's there.

require 'nmap/xml'
nmapfilerecords = 0
Nmap::XML.new('/Users/colemk1/Documents/Aptana Studio 3 Workspace/JumpSquares/public/uploads/nmapfile/nmapxml/21/scan.xml') do |xml|
    xml.each_host do |host|
      if "#{host.status}" == "down"            
      else
        nmapfilerecords += 1
      end
    end
   puts nmapfilerecords
end

Any help is appreciated

Это было полезно?

Решение

come to find out, the Nmap XML parser needs to have the FULL path.

setting the full path made it work correctly:

Nmap::XML.new('/Users/colemk1/Documents/Aptana Studio 3 Workspace/JumpSquares/public/' + @nmapfile.nmapxml.to_s) do |xml|

or use the rails root path

Nmap::XML.new("#{Rails.root}/public/" + @nmapfile.nmapxml.to_s) do |xml|
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top