获取“远程服务器返回错误:(500)语法错误,命令无法识别"当我尝试运行 FtpWebRequest.GetRequestStream [英] Get "The remote server returned an error: (500) Syntax error, command unrecognized" when I try to run FtpWebRequest.GetRequestStream

查看:56
本文介绍了获取“远程服务器返回错误:(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) 语法错误,命令无法识别.

为什么???

推荐答案

我通过以下方法解决了:

I solved it by using the following:

$ftp.KeepAlive = $false

这篇关于获取“远程服务器返回错误:(500)语法错误,命令无法识别"当我尝试运行 FtpWebRequest.GetRequestStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆