550 file unavailable error with FtpWebRequest class file upload. Works fine in FileZilla

前端 未结 4 638
借酒劲吻你
借酒劲吻你 2021-01-13 08:26

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

4条回答
  •  萌比男神i
    2021-01-13 09:07

    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)
        }
    }
    

提交回复
热议问题