forked from TEdit/Terraria-Map-Editor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathftp.ps1
86 lines (78 loc) · 2.94 KB
/
ftp.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$Username,
[Parameter()]
[string]$Password,
[Parameter(Mandatory=$True)]
[string]$Server
)
# Config
$files = Get-ChildItem .\build -Filter *.zip
Set-Location .\build
foreach ($LocalFile in $files)
{
$RemoteFile = $Server + "/" + [System.IO.Path]::GetFileName($LocalFile)
Write-Host "Uploading $LocalFile to $RemoteFile..."
# Create FTP Rquest Object
$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)
$FTPRequest.UseBinary = $true
$FTPRequest.UsePassive = $true
# Read the File for Upload
$FileContent = gc -en byte $LocalFile
$FTPRequest.ContentLength = $FileContent.Length
# Get Stream Request by bytes
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
# Cleanup
$Run.Close()
$Run.Dispose()
Write-Host "FTP done."
}
Set-Location ..\
$files = Get-ChildItem .\ -Filter teditversion.txt
foreach ($LocalFile in $files)
{
$RemoteFile = $Server + "/" + [System.IO.Path]::GetFileName($LocalFile)
Write-Host "Uploading $LocalFile to $RemoteFile..."
# Create FTP Rquest Object
$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)
$FTPRequest.UseBinary = $true
$FTPRequest.UsePassive = $true
# Read the File for Upload
$FileContent = gc -en byte $LocalFile
$FTPRequest.ContentLength = $FileContent.Length
# Get Stream Request by bytes
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
# Cleanup
$Run.Close()
$Run.Dispose()
Write-Host "FTP done."
}
#download
## # Create a FTPWebRequest
## $FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile)
## $FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
## $FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
## $FTPRequest.UseBinary = $true
## $FTPRequest.KeepAlive = $false
## # Send the ftp request
## $FTPResponse = $FTPRequest.GetResponse()
## # Get a download stream from the server response
## $ResponseStream = $FTPResponse.GetResponseStream()
## # Create the target file on the local system and the download buffer
## $LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create)
## [byte[]]$ReadBuffer = New-Object byte[] 1024
## # Loop through the download
## do {
## $ReadLength = $ResponseStream.Read($ReadBuffer,0,1024)
## $LocalFileFile.Write($ReadBuffer,0,$ReadLength)
## }
## while ($ReadLength -ne 0)