Powershell script difficulty - Using ps with TFTP with no ACKs

I’d like to use TFTP and UDP to send a file from one local computer (the client) to another local computer (the server) – in other words, purely a LAN transfer. Right now, I’m using the following setup:

On the server side, I am using Open TFTP Server (single port version found in the Files tab on the project’s SourceForge page).

On the client side, I have been using WinAgents TFTP Client which allows the user to specify the packet length (in this case 1400 bytes):

TFTP.exe -i -b1400 -v [DestinationIP] PUT [LocationOfLocalFile]

I have had no problems sending a 40mb file over this connection at various packet sizes up to 45000 with no loss of data; it is after all purely a LAN transfer.

For various reasons, I would like to replace the WinAgents TFTP Client with the following Powershell script. This isn’t something I’ve written but was found on sans[.]org as part of an interesting project several years ago. The script is unique in that it does not rely on ACKs from the server, but instead relies on waiting for a few milliseconds between sending each packet.

# Declare Configuration Values
[String] $localFile = "C:\Users\Computer1\Desktop\ABC_123.txt" # Default file name
[int] $opCode = 2 # Tftp Opcodes: 1=Read,2=Write,3=Data,4=Ack,5=Error
[String] $modeType = "octet" # TFTP Modes: octet, netascii, mail
[int] $transferPort = 69
[int] $waitAfterPacketMS = 10
$ipAddress = [system.net.IPAddress]::Parse("")

# Init Variables
[int] $packetNum = 1
$Enc = [System.Text.Encoding]::ASCII

# Create TFTP Write File Request Frame
$sndBuffer = @()
[byte[]] $sndBuffer += @([byte] 0x00)
$sndBuffer += @([byte] $opCode )
$sndBuffer += $Enc.GetBytes($localFile)
$sndBuffer += @([byte] 0x00)
$sndBuffer += $Enc.GetBytes($modeType)
$sndBuffer += @([byte] 0x00)

# Create Endpoints
$requestEnd = New-Object System.Net.IPEndPoint $ipAddress, 69

# Create Socket
$Saddrf = [System.Net.Sockets.AddressFamily]::InterNetwork
$Stype = [System.Net.Sockets.SocketType]::Dgram
$Ptype = [System.Net.Sockets.ProtocolType]::UDP
$Sock = New-Object System.Net.Sockets.Socket $saddrf, $stype, $ptype
$Sock.TTL = 26
# Send TFTP Write File Request Frame
$len = $Sock.Send($sndBuffer)
Start-Sleep -m $waitAfterPacketMS

# Create Binary Reader
$binaryReader = New-Object System.IO.BinaryReader([System.IO.File]::Open($localFile,
[System.IO.FileMode]::Open, [System.IO.FileAccess]::Read,
$transferEnd = New-Object System.Net.IPEndPoint $ipAddress, $transferPort
 $sndBuffer = @()
 $sndBuffer += @([byte] 0x00)
 $sndBuffer += @([byte] 0x03)
 $sndBuffer += @([byte] (($packetNum -shr 8) -bAnd 0xff))
 $sndBuffer += @([byte] ($packetNum -bAnd 0xff))
 $sndBuffer += @($binaryReader.ReadBytes(512))
 $len = $Sock.Send($sndBuffer)
 Start-Sleep -m $waitAfterPacketMS
until ($sndBuffer.Length -lt 516)

Using this script as-is, I can successfully transfer files with no data loss. Unfortunately, the script doesn’t seem to handle packets larger than 512 bytes.

Changing the following lines at the end of the script to reflect a larger packet size creates an error on the server side

$sndBuffer += @($binaryReader.ReadBytes(512))
until ($sndBuffer.Length -lt 516)

Does anyone know how to change this script so that larger packet sizes could be sent?

Because its written in Powershell, does this mean that the script operates within some system-wide default? Can the default be overwritten? Is there an alternative that would allow the packet size to be increased?