Ruby on rails SyntaxError:net sftp.rb:48:语法错误,意外的tCONSTANT将Ruby中的“文件传输完成”从Filezilla客户端放置到本地主机

Ruby on rails SyntaxError:net sftp.rb:48:语法错误,意外的tCONSTANT将Ruby中的“文件传输完成”从Filezilla客户端放置到本地主机,ruby-on-rails,localhost,syntax-error,filezilla,Ruby On Rails,Localhost,Syntax Error,Filezilla,我正在使用ConEmu运行JRuby进行自动化测试,以将文件从Filezila客户端放到本地主机。不应将其发送到远程服务器。尝试在Ruby中运行以下代码以建立连接时出错。在这里传输文件并不重要 抱歉:很快就会好的 require 'net-ssh' require 'net-sftp' require 'dir' local_path = 'D:\Rubynetssh' remote_path = '/cguclaim/virtual/data/logs/gwlogs/ClaimCenter/

我正在使用ConEmu运行JRuby进行自动化测试,以将文件从Filezila客户端放到本地主机。不应将其发送到远程服务器。尝试在Ruby中运行以下代码以建立连接时出错。在这里传输文件并不重要

抱歉:很快就会好的

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'
当我运行下面的命令时

jruby net-sftp.rb

这将导致此错误语法

SyntaxError:net sftp.rb:48:语法错误,意外的tCONSTANT放置“文件传输完成”

*编辑*

***现在,您将代码放入注释中,它显示为错误,如下所示:

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

下面编写的代码更适合我建立从Filezilla到ConEmu的连接,但现在我需要进入ClaimCenter文件夹查看文件是否存在

require "net/ssh"
require "net/sftp"

@hostname = "server"
@username = "admin"
@password = "password1"
@cmd = "ls -la"

res = ""
ssh = Net::SSH.start(@hostname, @username, password: @password) do |ssh|
res = ssh.exec!(@cmd)
 end

puts res

请先把你的订单修好。很难确定街区在哪里。请注意这一行代码:puts“Disconnecting from remote server”(从远程服务器断开连接)开始的qoute与您的终端qoute不同。感谢您在开始和结束引用中更正我-我没有注意到这一点。我不确定我是否可以缩进它,因为它实际上是一个代码的一部分?我不认为你不能缩进它。只需编辑你的问题,并在你的问题代码中做适当的意图。缩进是一种最佳实践,如果没有正确的缩进,阅读代码是非常困难的。好的,谢谢你,现在看看。现在,当我运行jruby net-sftp.rb时,出现了以下语法错误:net sftp.rb:46:语法错误,下面出现了意外的kENDError消息:LoadError:没有这样的文件要加载-net ssh require at org/jruby/RubyKernel.java:939 require at C:/jruby-9.0.4.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54 at net sftp.rb:1