获取“远程服务器返回错误:(500)语法错误,命令无法识别”当我尝试运行FtpWebRequest.GetRequestStream时 [英] Get "The remote server returned an error: (500) Syntax error, command unrecognized" when I try to run FtpWebRequest.GetRequestStream
本文介绍了获取“远程服务器返回错误:(500)语法错误,命令无法识别”当我尝试运行FtpWebRequest.GetRequestStream时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码发送文件到FTP服务器。
I have following code to send files to a FTP server.
function FtpUploader(
[string]$uri,
[string]$localeFile,
[string]$user = "ftp",
[string]$password = "ftp",
[int] $timeout = 20000
){
trap {
Write-Host ("ERROR: " + $_) -Foregroundcolor Red
return $false
}
$ftp = [System.Net.FtpWebRequest]::Create($uri)
$ftp = [System.Net.FtpWebRequest]$ftp
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$ftp.Credentials = new-object System.Net.NetworkCredential($user, $password)
$ftp.Timeout = $timeout
$ftp.UseBinary = $false
$ftp.UsePassive = $true
$content = Get-Content -en byte $localeFile
$rs = $ftp.GetRequestStream()
$rs.Write($content, 0, $content.Length)
$rs.Close()
$rs.Dispose()
return $true
}
我使用的URI是 ftp://xxx.xxx.xxx.xxx/aaa /bbb/ccc/R1ACTIVE.TXT 。
FTP服务器是vsftpd
The URI I use is "ftp://xxx.xxx.xxx.xxx/aaa/bbb/ccc/R1ACTIVE.TXT". The FTP server is vsftpd
大部分时间都是上传文件。但是,有时我在运行 $ ftp.GetRequestStream()
时遇到以下错误:
Most of the time, the file is uploaded. But sometime I get following error when it try to run $ftp.GetRequestStream()
:
远程服务器返回一个错误:(500)语法错误,命令无法识别。
The remote server returned an error: (500) Syntax error, command unrecognized.
为什么???
Why???
解决方案
I solved it by using the following:
$ false
这篇关于获取“远程服务器返回错误:(500)语法错误,命令无法识别”当我尝试运行FtpWebRequest.GetRequestStream时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文