使用PowerShell进行FTP请求时出现错误530

时间:2015-02-05 16:47:49

标签: powershell ftp

我试图通过PowerShell脚本从我的FTP服务器获得响应。为此,我写了以下内容:

$sourceuri = "<string>"
$targetpath = "<string>"
$username = "<string>"
$password = "<string>"

# Create a FTPWebRequest object to handle the connection to the ftp server
$ftprequest = [System.Net.FtpWebRequest]::create($sourceuri)

# set the request's network credentials for an authenticated connection
$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password, $sourceuri)

$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$ftprequest.UseBinary = $true
$ftprequest.KeepAlive = $false

# send the ftp request to the server
$ftpresponse = $ftprequest.GetResponse()

在脚本执行时,它返回错误530,表示我没有登录。我没有PowerShell经验,也不确定我需要添加什么来修复此错误

1 个答案:

答案 0 :(得分:0)

问题可能是这一行

$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password, $sourceuri)

[System.Net.NetworkCredential]的唯一constructor that accepts 3 parameters正在寻找用户名,密码,。您$sourceuridomain$sourceuri是FTP网址,不是吗?我认为如果你只是使用基本的FTP凭证,你需要只有用户名和密码。

$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password)