Search code examples
securitypowershellftpsecurestring

powershell and secureString class


Attempting to access an FTP site, I can use a plain text password in credentials and it works fine, but when I use a SecureString it fails to authenticate. Examples:

$pw = "mypw"
$ftp = [system.net.ftpwebrequest] [system.net.webrequest]::create("ftp:myserver")
$ftp.Credentials  = new-object system.net.networkcredential("myuid", $pw)

works fine. But the following fails

$pw = "mypw"
$ftp = [system.net.ftpwebrequest] [system.net.webrequest]::create("ftp:myserver")
$ss = convertto-securestring -asplaintext -force $pw
$ftp.Credentials  = new-object system.net.networkcredential("myuid", $ss)

But that fails to authenticate. What am I misunderstanding?

(BTW I know that I don't want plaintext pw in my script. This is just an example.)


Solution

  • This is because FTP cannot handle anything other than plain text username and passwords unless you are using secure FTP. Is there some confusion here?