开发者

Requesting another server for file exist in ruby on rails

开发者 https://www.devze.com 2023-02-12 19:39 出处:网络
I have a condition where I need to check for the file in another server, if that file exi开发者_如何学运维sts I need to delete from the current server. Can any body help me.You can place ascript on an

I have a condition where I need to check for the file in another server, if that file exi开发者_如何学运维sts I need to delete from the current server. Can any body help me.


You can place a script on another server and ask it in restful way to perform that tasks for you:

http://another.server/exists/:file_name
http://another.server/delete/:file_name

but you will have to think about security aspects of this solution.

Also take a look on executing remote commands via ssh: http://bashcurescancer.com/run_remote_commands_with_ssh.html. Combined with using ssh "without password" it can be acceptable solution to run command line program that run what you need.


Just write a ruby script and do something along the line with:

require "open-uri"

file_name = "file.name"

begin
  file = open("http://www.example.com/#{file_name}")
  File.delete("path_to" + file_name)
  p "File #{file_name} deleted"
rescue
  p "File not found"
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号