0
votes

I'm trying to get a response from my FTP server via a PowerShell Script. To do this I have written the following:

$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()

Upon script execution it returns error 530 saying that I am not logged in. I have no PowerShell experience and am unsure of what I need to add to fix this error

1

1 Answers

0
votes

The problem could be this line

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

The only constructor that accepts 3 parameters for [System.Net.NetworkCredential] is looking for username, password, domain. You have $sourceuri in place for domain.$sourceuri is the FTP url is it not? I should think that if you are just using basic FTP credentials you need to just have username and password.

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