FTP列出文件列表
#定义FTP服务器地址
$ftpURL = "ftp://192.168.12.6/"
#定义登录FTP服务器的账户及密码
$username = "testj\adadmin"
$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()