我不能连续两次上传同一个文件(第二次,内容更新),我得到以下内容,我该如何解决?
Connected successfully uploading file: /tmp/Mall_bill_extract_20120213_170429_2.csv
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-sftp-2.0.5/lib/net/sftp/operations/upload.rb:313:in `on_open'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `to_proc'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-sftp-2.0.5/lib/net/sftp/request.rb:87:in `call'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-sftp-2.0.5/lib/net/sftp/request.rb:87:in `respond_to'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:948:in `dispatch_request'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:911:in `when_channel_polled'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `to_proc'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/channel.rb:311:in `call'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/channel.rb:311:in `process'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:214:in `preprocess'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:214:in `each'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:214:in `preprocess'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:197:in `process'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:161:in `loop'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:161:in `loop_forever'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:161:in `loop'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:802:in `loop'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@vitality_mall/gems/net-sftp-2.0.5/lib/net/sftp.rb:35:in `start'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/app/controllers/report_purchases_employer_controller.rb:139:in `export_to_bill_csv'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/base.rb:1253:in `send'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/base.rb:1253:in `perform_action_without_filters'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/filters.rb:617:in `call_filters'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/base.rb:524:in `send'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/base.rb:524:in `process_without_filters'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/session_management.rb:134:in `process'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/base.rb:392:in `process'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:183:in `handle_request'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:123:in `dispatch'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in `synchronize'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in `dispatch'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:39:in `dispatch'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/railties/lib/webrick_server.rb:103:in `handle_dispatch'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/railties/lib/webrick_server.rb:74:in `service'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:162:in `start'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:95:in `start'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:92:in `each'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:92:in `start'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:23:in `start'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:82:in `start'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/railties/lib/webrick_server.rb:60:in `dispatch'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/railties/lib/commands/servers/webrick.rb:66
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/vendor/rails/railties/lib/commands/server.rb:49
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Users/kamilski81/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/Users/kamilski81/Sites/pe/rails-apps/vitality_mall/script/server:3
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@global/gems/ruby-debug-ide-0.4.17.beta5/lib/ruby-debug-ide.rb:112:in `debug_load'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@global/gems/ruby-debug-ide-0.4.17.beta5/lib/ruby-debug-ide.rb:112:in `debug_program'
/Users/kamilski81/.rvm/gems/ruby-1.8.7-p352@global/gems/ruby-debug-ide-0.4.17.beta5/bin/rdebug-ide:87
-e:1:in `load'
-e:1
这是代码:
begin
Net::SFTP.start('localhost', 'user', :password=>'pass') do |sftp|
sftp.upload file_location, "/test/outbound_transactions/#{file_name}"
end
rescue => ex
puts ex.backtrace
end
答案 0 :(得分:1)
为了数据安全,您应该:
.bak
版本。原因是,如果代码或连接由于某种原因失败,您希望其中一个版本可用。
这也可以解决你所看到的问题。
我看到FTP主机在上传后立即锁定文件。我不知道为什么,因为,当他们的服务器搞砸了它使我无法删除文件。因此,他们可以在上传后立即锁定/更改权限或更改文件的所有权。
回溯并没有多大帮助,因为我们没有收到ex
中包含的消息。你应该这样做:
puts ex.message
或:
puts ex.to_s
在puts ex.backtrace
之前获取实际消息。
引发异常的代码也没有告诉我们多少:
# Called when an +open+ request finishes. Raises StatusException if the
# open failed, otherwise it calls #write_next_chunk to begin sending
# data to the remote server.
def on_open(response)
@active -= 1
file = response.request[:file]
raise StatusException.new(response, "open #{file.remote}") unless response.ok?
[...]
所以puts ex.message
会帮助你。
此外,upload
是异步的,因此您可能希望添加wait
。这来自the docs:
异步启动从本地到远程的上传。此方法将返回一个新的Net :: SFTP :: Operations :: Upload实例,并且需要运行事件循环才能使上载进行。有关如何使用此方法的完整讨论,请参阅Net :: SFTP :: Operations :: Upload。
uploader = sftp.upload("/local/path", "/remote/path")
uploader.wait