Compass / sass remote temation via sftp / scp with alternate port

I am trying to get compass / sass to view the changes on my local computer and reflect these changes remotely using a config.rb config script. net::sftp works, but my server requires its own ssh port. I could not find any mods to get sftp to work with an alternate port, so I'm trying net:scp now, the problem is that I donโ€™t know the correct command structure to load using net: scp and would like to see if anyone can help me sometime. Here is my code:

  # Require any additional compass plugins here. require 'net/ssh' require 'net/scp' # SFTP Connection Details - Does not support alternate ports os SSHKeys, but could with mods remote_theme_dir_absolute = '/home2/trinsic/public_html/scottrlarson.com/sites/all/themes/ gateway_symbology_zen/css' sftp_host = 'xxx.xxx.xxx.xxx' # Can be an IP sftp_user = 'user' # SFTP Username sftp_pass = 'password' # SFTP Password # Callback to be used when a file change is written. This will upload to a remote WP install on_stylesheet_saved do |filename| $local_path_to_css_file = css_dir + '/' + File.basename(filename) Net::SSH.start( sftp_host, sftp_user, {:password => sftp_pass,:port => 2222} ) do ssh.scp.upload! $local_path_to_css_file, remote_theme_dir_absolute + '/' + File.basename(filename) end puts ">>>> Compass is polling for changes. Press Ctrl-C to Stop" end # # This file is only needed for Compass/Sass integration. If you are not using # Compass, you may safely ignore or delete this file. # # If you'd like to learn more about Sass and Compass, see the sass/README.txt # file for more information. # # Change this to :production when ready to deploy the CSS to the live server. environment = :development #environment = :production # In development, we can turn on the FireSass-compatible debug_info. firesass = false #firesass = true # Location of the theme resources. css_dir = "css" sass_dir = "sass" extensions_dir = "sass-extensions" images_dir = "images" javascripts_dir = "js" # Require any additional compass plugins installed on your system. #require 'ninesixty' #require 'zen-grids' # Assuming this theme is in sites/*/themes/THEMENAME, you can add the partials # included with a module by uncommenting and modifying one of the lines below: #add_import_path "../../../default/modules/FOO" #add_import_path "../../../all/modules/FOO" #add_import_path "../../../../modules/FOO" ## ## You probably don't need to edit anything below this. ## # You can select your preferred output style here (can be overridden via the command line): # output_style = :expanded or :nested or :compact or :compressed output_style = (environment == :development) ? :expanded : :compressed # To enable relative paths to assets via compass helper functions. Since Drupal # themes can be installed in multiple locations, we don't need to worry about # the absolute path to the theme from the server root. relative_assets = true # To disable debugging comments that display the original location of your selectors. Uncomment: # line_comments = false # Pass options to sass. For development, we turn on the FireSass-compatible # debug_info if the firesass config variable above is true. sass_options = (environment == :development && firesass == true) ? {:debug_info => true} : {} 

I get an error when running the command: compass watch:

 NoMethodError on line ["17"] of K: undefined method `upload!' for #<Net::SSH::Co nnection::Session:0x000000036bb220> Run with --trace to see the full backtrace 
+1
source share
1 answer

I also needed a solution, but I could not find a satisfactory answer anywhere. After reading the Ruby Net :: ssh documentation and some Compass source, this is my solution to upload CSS and sourcemap to a remote SSH server with a non-standard port and public key authorization:

First, make sure you have the necessary stones installed.

 sudo gem install net-ssh net-sftp 

then add this to your config.rb

 # Add this to the first lines of your config.rb require 'net/ssh' require 'net/sftp' ... # Your normal compass config comes here ... # At the end of your config.rb add the config for the upload code remote_theme_dir_absolute = '/path/to/my/remote/stylesheets' sftp_host = 'ssh_host' # Can be an IP sftp_user = 'ssh_user' # SFTP Username on_stylesheet_saved do |filename| # You can use the ssh-agent for authorisation. # In this case you can remove the :passphrase from the config and set :use_agent => true. Net::SFTP.start( sftp_host, sftp_user , :port => 10022, :keys_only => true, :keys => ['/path/to/my/private/id_rsa'], :auth_methods => ['publickey'], :passphrase => 'my_secret_passphrase', :use_agent => false, :verbose => :warn ) do |sftp| puts sftp.upload! css_dir + '/app.css', remote_theme_dir_absolute + '/' + 'app.css' end end on_sourcemap_saved do |filename| # You can use the ssh-agent for authorisation. # In this case you can remove the :passphrase from the config and set :use_agent true. Net::SFTP.start( sftp_host, sftp_user , :port => 10022, :keys_only => true, :keys => ['/path/to/my/private/id_rsa'], :auth_methods => ['publickey'], :passphrase => 'my_secret_passphrase', :use_agent => false, :verbose => :warn ) do |sftp| puts sftp.upload! css_dir + '/app.css.map', remote_theme_dir_absolute + '/' + 'app.css.map' end end 

It was pretty simple trial and error until it worked for me. Some points of failure:

  • If ssh-agent is not available, the connection will fail until you explicitly set :ssh_agent => false
  • If you do not limit the keys to available keys: all available keys will be checked one by one. If you use ssh-agent and have more than 3 keys, chiki is installed that the remote server will close the connection if you try too many keys that are invalid for the server that you are currently connecting.
  • For any connection issues, set the level of detail to :verbose => :debug to see what happens. Remember to stop the compass watch and restart to ensure that the settings are changed.
0
source

All Articles