Advertisement
sopyanx

func_fetch

Mar 24th, 2019
1,743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #########################################################
  2. # Wrapper for /tools fetch
  3. # Input:
  4. # mode
  5. # upload=yes/no
  6. # user
  7. # password
  8. # address
  9. # host
  10. # httpdata
  11. # httpmethod
  12. # check-certificate
  13. # src-path
  14. # dst-path
  15. # ascii=yes/no
  16. # url
  17. # resfile
  18.  
  19. :local res "fetchresult.txt"
  20. :if ([:len $resfile]>0) do={:set res $resfile}
  21. #:put $res
  22.  
  23. :local cmd "/tool fetch"
  24. :if ([:len $mode]>0) do={:set cmd "$cmd mode=$mode"}
  25. :if ([:len $upload]>0) do={:set cmd "$cmd upload=$upload"}
  26. :if ([:len $user]>0) do={:set cmd "$cmd user=\"$user\""}
  27. :if ([:len $password]>0) do={:set cmd "$cmd password=\"$password\""}
  28. :if ([:len $address]>0) do={:set cmd "$cmd address=\"$address\""}
  29. :if ([:len $host]>0) do={:set cmd "$cmd host=\"$host\""}
  30. :if ([:len $"http-data"]>0) do={:set cmd "$cmd http-data=\"$"http-data"\""}
  31. :if ([:len $"http-method"]>0) do={:set cmd "$cmd http-method=\"$"http-method"\""}
  32. :if ([:len $"check-certificate"]>0) do={:set cmd "$cmd check-certificate=\"$"check-certificate"\""}
  33. :if ([:len $"src-path"]>0) do={:set cmd "$cmd src-path=\"$"src-path"\""}
  34. :if ([:len $"dst-path"]>0) do={:set cmd "$cmd dst-path=\"$"dst-path"\""}
  35. :if ([:len $ascii]>0) do={:set cmd "$cmd ascii=\"$ascii\""}
  36. :if ([:len $url]>0) do={:set cmd "$cmd url=\"$url\""}
  37.  
  38. :put ">> $cmd"
  39.  
  40. :global FETCHRESULT
  41. :set FETCHRESULT "none"
  42.  
  43. :local script "\
  44. :global FETCHRESULT;\
  45. :do {\
  46. $cmd;\
  47. :set FETCHRESULT \"success\";\
  48. } on-error={\
  49. :set FETCHRESULT \"failed\";\
  50. }\
  51. "
  52. :execute script=$script file=$res
  53. :local cnt 0
  54. #:put "$cnt -> $FETCHRESULT"
  55. :while ($cnt<100 and $FETCHRESULT="none") do={
  56. :delay 1s
  57. :set $cnt ($cnt+1)
  58. #:put "$cnt -> $FETCHRESULT"
  59. }
  60. :local content [/file get [find name=$res] content]
  61. #:put $content
  62. if ($content~"finished") do={:return "success"}
  63. :return $FETCHRESULT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement