FTP列出文件列表

#定义FTP服务器地址
$ftpURL = "ftp://192.168.12.6/"
#定义登录FTP服务器的账户及密码
$username = "testjadadmin"
$userpass = "boc.123"

$ftpList = [system.net.ftpwebrequest] [system.net.webrequest]::create("ftp://192.168.12.6/")
$ftpList.Credentials = New-Object System.Net.NetworkCredential($username,$userpass)
$ftpList.Method = [system.net.WebRequestMethods+ftp]::ListDirectory
#显示文件详细信息
#$ftpList.Method = [system.net.WebRequestMethods+ftp]::ListDirectoryDetails
$ftpResponse = $ftpList.GetResponse()
$ftpStream = New-Object System.Io.StreamReader($ftpResponse.getresponsestream(),[System.Text.Encoding]::UTF8)
while(-not $ftpStream.EndOfStream)
{$ftpStream.ReadLine()|out-file d:m.txt -append}
$ftpStream.Close()
$ftpResponse.Close()

原文地址:https://www.cnblogs.com/dreamer-fish/p/3268510.html