大きなファイルを転送します。 メールによるダウンロードリンクの自動受信

多くの場合、ユーザーはローカルネットワーク内外で大きなファイルを転送する必要があります。 たとえば、Pierrotは10ギガバイトのドキュメントをMalvineに送信する必要があります。 ユーザーは通常、リンクのコピーなどを気にしたくないので、ここでは企業のメールは救助に来ません。 それらが同じローカルネットワーク上にある場合、共有フォルダーが役立ちます。また、それらが国の異なる端にある場合...原則として、FTPサーバーを使用する必要があります。FTPサーバーは、多くの場合、あまり便利ではありません。



そこで、ローカルネットワーク上で大きなファイルを送信するための便利で制御されたサービスを作成するというアイデアが生まれました。



PowerShell実装、Windowsプラットフォーム。



要件:





仕組み:







スクリプトの説明:





注:ユーザーが共有フォルダーを持つサーバーのAdministratorsグループのメンバーである場合、所有者= Administratorsグループです。このため、管理メールボックスはスクリプトで指定されます。



スクリプトでは、次のパラメーターを必要なものに変更する必要があります。



$path = "C:\UPLOAD\" #    $path1 = "C:\inetpub\wwwroot\UPLOAD\" #  -,  
      
      





Send_URL関数で、パラメーターを変更します。



 $day = -30 #      "+(-1*$day)+" .      . $mail_domain = "@mydomain.com" $owner_domain = "mydomain\\" $mail_admin = "admin@mydomain.com" $mail_server = "mail.mydomain.com" $http = "http://web.mydomain.com/UPLOAD/"
      
      





ファイルの所有者の正しい決定は、ドメイン内でのみ可能です。 ドメインなしでは、共有フォルダーを持つコンピューター上にユーザーアカウントを作成し、それらをユーザーに関連付ける必要があります。



コード:



 # Func.ps1 ################################### #    hars@bk.ru  2015. Function Send_URL($File,$path,$path1){ ###       ################################################## $day = -30 #      "+(-1*$day)+" .      . $mail_domain = "@mydomain.com" $owner_domain = "mydomain\\" $mail_admin = "admin@mydomain.com" $mail_server = "mail.mydomain.com" $http = "http://web.mydomain.com/UPLOAD/" ################################################## $File_nm = $File.Trim() #           $File = $File -replace '\[|\]','`$0' #  []    $owner = ( Get-Acl ($path + $File) ).Owner #   ##############  email if( $owner -like "*dministrator*" -or !$owner ){ $mail = $mail_admin }else{ $mail = ($owner -ireplace($owner_domain,"")) + $mail_domain } ###################################### #$md5 = Get-FileHash ($path + $File) -Algorithm MD5 #$File_url = $md5.Hash + ".zip" #$File_new = $path1 + $md5.Hash + ".zip" #############     if($File_nm.length > 100){ $File_url = $File_nm.Substring(0,100) }else{ $File_url = $File_nm } ############################################# #############   @!{}%$#''&` $File_url = $File_url -ireplace("#","") $File_url = $File_url -ireplace("%","") $File_url = $File_url -ireplace("$","") $File_url = $File_url -ireplace("&","_") $File_url = $File_url -ireplace("{","(") $File_url = $File_url -ireplace("}",")") $File_url = $File_url -ireplace('`',"") $File_url = $File_url -ireplace('"',"") $File_url = $File_url -ireplace("'","") $File_url = $File_url -ireplace("~","") $File_url = $File_url -ireplace(" ","_") ######################################### #        $File_url = $mail + "_" + $File_url #    $File_new = $path1 + $File_url #    - Move-Item -path ( $path + $File ) -destination $File_new -force -EA SilentlyContinue #-whatif #             if( Get-ChildItem $File_new -EA SilentlyContinue){ write-host "OK" #  #     , #        , #    ,         $F = Get-ChildItem $File_new $F.LastWriteTime = Get-date }else{ write-host "NO" #   break #   } #   $colItems = (Get-ChildItem $File_new | Measure-Object -property length -sum) $colSize = "{0:N2}" -f ($colItems.sum / 1MB) + " Mb" ###################################### #  $Body = "<b>: </b><a href='" + $http + $File_url +"'>" + $File_nm + " (" + $colSize + ")</a><br/>       "+(-1*$day)+" .      ." #  Send-MailMessage -to $mail -from $mail_admin -subject " " -BodyAsHtml $Body -Encoding UTF8 -SmtpServer $mail_server #  ,   if($mail -inotlike $mail_admin){ Send-MailMessage -to $mail_admin -from $mail -subject " " -BodyAsHtml $Body -Encoding UTF8 -SmtpServer $mail_server } Write-Host $owner $mail $Body #       ###################################### #    -       get-childitem $path1 *.zip | where {$_.lastwritetime -le (get-date).adddays($day) } | del -Recurse -Force } ########################################################################################## ########################################################################################## ########################################################################################## ########################################################################################## ########################################################################################## # Send_URL.ps1 ################################### #    hars@bk.ru  2015. #        # powershell.exe "C:\Scripts\Send_URL.ps1" -NoLogo -NonInteractive -WindowStyle Hidden <# ."C:\scripts\Func.ps1" #    .   (),  . #> ###       ################################################## $path = "C:\UPLOAD\" #    $path1 = "C:\inetpub\wwwroot\UPLOAD\" #  -,   ################################################## #    ZIP  Get-ChildItem $path -Recurse -Exclude *.zip | %{ Remove-Item $_ -Force -Recurse } #      $flist = get-childitem $path"*.zip" #-recurse #  ZIP ,         $flist | ForEach-Object{ Send_URL $_.PSChildName $path $path1 } #   html    #  index.html  ,  ""     #<html><head><meta http-equiv="refresh" content="0;url=http://www.yandex.ru" /></head></html> #copy C:\inetpub\wwwroot\index.html C:\inetpub\wwwroot\UPLOAD\index.html -Force #    -,    New-Item $path" ZIP ,  .txt" -type file -Force ################################### ################################### ################################### # DeleteOldFiles.ps1 ################################### #  .     . #    hars@bk.ru  2015. #        # powershell.exe "C:\Scripts\DeleteOldFiles.ps1" -NoLogo -NonInteractive -WindowStyle Hidden ###       ################################################## $ClearFolder = "C:\inetpub\wwwroot\UPLOAD\" #    $day = -14 #        ################################################## # oldDel            #         14 ,    function oldDel($folder,$day){ get-childitem $folder * | where {$_.lastwritetime -le (get-date).adddays($day) } | del -Recurse -Force #-WhatIf } oldDel $ClearFolder $day
      
      






All Articles