我试图通过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经验,也不确定我需要添加什么来修复此错误
答案 0 :(得分:0)
问题可能是这一行
$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password, $sourceuri)
[System.Net.NetworkCredential]
的唯一constructor that accepts 3 parameters正在寻找用户名,密码,域。您$sourceuri
已domain
。$sourceuri
是FTP网址,不是吗?我认为如果你只是使用基本的FTP凭证,你需要只有用户名和密码。
$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password)