2015-02-05 95 views
0

我试图通过PowerShell脚本从FTP服务器获取响应。要做到这一点,我写了下面的:使用PowerShell发送FTP请求时出现错误530

$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

这个问题可能是这条线

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

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

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

$ sourceuri是一个我相信的字符串。拿出$ sourceuri将错误更改为550错误,我不知道如何修复 – 2015-02-05 17:38:34

+0

@NickG这只是表示权限被拒绝。 '$ sourceuri'是一个webaddress是否正确?你可以在浏览器中使用这些凭据吗?它使用域凭据吗? – Matt 2015-02-05 17:41:39

+0

证书在浏览器中工作。我刚刚运行了另一个脚本,它列出了我的shell中的目录并且工作正常。然而,下载脚本会抛出550错误 – 2015-02-05 18:11:46

相关问题