I\'m searched and found other questions on this but none have solved my issues. I\'m trying to upload a file via FTP using sample MSDN code. I get the The remote server retu
This answer is for Steen and contains a PowerShell equivalent to the code in http://support.microsoft.com/kb/2134299 below. I don't have a system that has the non-compliant behavior to test against so you'll need to try it yourself.
function SetMethodRequiresCWD() {
[Type] $requestType = [System.Net.FtpWebRequest]
[System.Reflection.FieldInfo] $methodInfoField = $requestType.GetField("m_MethodInfo", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)
[Type] $methodInfoType = $methodInfoField.FieldType
[System.Reflection.FieldInfo] $knownMethodsField = $methodInfoType.GetField("KnownMethodInfo", [System.Reflection.BindingFlags]::Static -bor [System.Reflection.BindingFlags]::NonPublic)
[Array] $knownMethodsArray = [Array]$knownMethodsField.GetValue($null);
[System.Reflection.FieldInfo] $flagsField = $methodInfoType.GetField("Flags", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)
[int] $MustChangeWorkingDirectoryToPath = 0x100
ForEach ($knownMethod In $knownMethodsArray) {
[int] $flags = [int]$flagsField.GetValue($knownMethod)
$flags = $flags -bor $MustChangeWorkingDirectoryToPath
$flagsField.SetValue($knownMethod, $flags)
}
}