I am doing Automation testing running JRuby with ConEmu to put files from my Filezila Client to my local host. It should not be to the remote server. Getting errors when I try running the below code in Ruby for establishing the connection. Transferring files here are not as important.
APOLOGIES: Will fix soon.
require 'net-ssh'
require 'net-sftp'
require 'dir'
local_path = 'D:\Rubynetssh'
remote_path = '/cguclaim/virtual/data/logs/gwlogs/ClaimCenter/'
file_perm = 0644
dir_perm = 0755
puts 'Connecting to remote server'
Net::SSH.start('server', 'admin', 'password1') do |ssh|
ssh.sftp.connect do |sftp|
puts 'Checking for files which need updating'
Find.find(local_path) do |file|
next if File.stat(file).directory?
local_file = "#{dir}/#{file}"
remote_file = remote_path + local_file.sub(local_path, '')
begin
remote_dir = File.dirname(remote_file)
sftp.stat(remote_dir)
rescue Net::SFTP::Operations::StatusException => e
raise unless e.code == 2
sftp.mkdir(remote_dir, :permissions => dir_perm)
end
begin
rstat = sftp.stat(remote_file)
rescue Net::SFTP::Operations::StatusException => e
raise unless e.code == 2
sftp.put_file(local_file, remote_file)
sftp.setstat(remote_file, :permissions => file_perm)
next
end
if File.stat(local_file).mtime > Time.at(rstat.mtime)
puts "Copying #{local_file} to #{remote_file}"
sftp.put_file(local_file, remote_file)
end
end
end
puts 'Disconnecting from remote server'
end
puts 'File transfer complete'
When I run the command below
jruby net-sftp.rb
this results in this error syntax
SyntaxError: net-sftp.rb:48: syntax error, unexpected tCONSTANT puts 'File transfer complete'
* EDIT *
***Now that you put in the code in the comment it comes up as error as shown below:
1. LoadError: no such file to load -- net-ssh
2. require at org/jruby/RubyKernel.java:939
3. require at
4. C:/jruby-9.0.4.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54
5. <top> at net-sftp.rb:1