Aqui está uma ideia básica de como isso pode ser feito:
Use um script PowerShell para iniciar um servidor HTTP simples que hospeda uma pasta compartilhada, permitindo o upload e download de arquivos.
Exemplo de Servidor HTTP:
powershell
CopiarEditar
$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add("http://+:8080/")
Write-Host "Servidor iniciado. Acesse http://$(hostname):8080 ou http://46.50.4.102:8080 no outro PC."
$context = $listener.GetContext()
$request = $context.Request
$response = $context.Response
if ($request.HttpMethod -eq "GET") {
$response.ContentType = "text/html"
<h1>Envie um arquivo</h1>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="Enviar" />
$buffer = [System.Text.Encoding]::UTF8.GetBytes($html)
$response.OutputStream.Write($buffer, 0, $buffer.Length)
} elseif ($request.HttpMethod -eq "POST") {
$boundary = $request.ContentType.Split("; ")[1].Split("=")[1]
$reader = New-Object IO.StreamReader($request.InputStream)
$body = $reader.ReadToEnd()
# Extração do arquivo (simples, ajustável conforme a necessidade)
$start = $body.IndexOf("Content-Type:") + 13
$start = $body.IndexOf("`r`n`r`n", $start) + 4
$end = $body.LastIndexOf("`r`n--$boundary--")
$fileContent = $body.Substring($start, $end - $start)
$filePath = "C:\PastaServidor\upload_" + (Get-Date -Format "yyyyMMdd_HHmmss") + ".txt" # Salve como desejar
[System.IO.File]::WriteAllBytes($filePath, [System.Text.Encoding]::ASCII.GetBytes($fileContent))
$response.ContentType = "text/plain"
$response.StatusCode = 200
$buffer = [System.Text.Encoding]::UTF8.GetBytes("Arquivo recebido e salvo em $filePath.")
$response.OutputStream.Write($buffer, 0, $buffer.Length)
Salve este script como Servidor.ps1 no PC servidor.
Execute-o em PowerShell com privilégios de administrador para abrir a porta 8080.
Você pode usar PowerShell para enviar arquivos via HTTP para o servidor.
Exemplo de Cliente HTTP:
powershell
CopiarEditar
$filePath = "C:\Caminho\Para\Seu\Arquivo.txt"
$serverUrl = "http://46.50.4.102:8080"
$boundary = "----WebKitFormBoundary" + [System.Guid]::NewGuid().ToString("N")
$headers["Content-Type"] = "multipart/form-data; boundary=$boundary"
$fileContent = Get-Content $filePath -Raw
Content-Disposition: form-data; name="file"; filename="$(Split-Path $filePath -Leaf)"
Invoke-WebRequest -Uri $serverUrl -Method POST -Headers $headers -Body $formData
Salve este script como Cliente.ps1 no outro PC.
Substitua o caminho do arquivo e o URL do servidor conforme necessário.
Execute o script para enviar o arquivo para o servidor.
Certifique-se de que os PCs estejam na mesma rede e que o firewall permita o tráfego na porta 8080.
Para maior segurança, configure autenticação no servidor ou use HTTPS.
Você pode ajustar os scripts para transferir diferentes tipos de arquivos e aprimorar a interface HTML do servidor.
Se precisar de ajuda para a