Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell FTP赢得';t列出服务器上的文件_Powershell_Ftp - Fatal编程技术网

Powershell FTP赢得';t列出服务器上的文件

Powershell FTP赢得';t列出服务器上的文件,powershell,ftp,Powershell,Ftp,我想为ZyWall USG 20制作一个备份脚本。 我使用此Powershell代码获取目录中的内容列表: [System.Net.FtpWebRequest]$ftp = [System.Net.WebRequest]::Create("ftp://*server*/*path*") $ftp.Credentials = New-Object System.Net.NetworkCredential("*user*","*password*") $ftp.Method = [System.N

我想为ZyWall USG 20制作一个备份脚本。
我使用此Powershell代码获取目录中的内容列表:

[System.Net.FtpWebRequest]$ftp = [System.Net.WebRequest]::Create("ftp://*server*/*path*")
$ftp.Credentials = New-Object System.Net.NetworkCredential("*user*","*password*") 
$ftp.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
$response = $ftp.getresponse()
echo $response
我希望得到所有文件的列表..
相反,我得到的是:

PS Z:\> ...\list-files-test.ps1


ContentLength           : -1
Headers                 : {}
SupportsHeaders         : True
ResponseUri             : ftp://*server*/*path*/
StatusCode              : OpeningData
StatusDescription       : 150 Opening BINARY mode data connection for file list

LastModified            : 01.01.0001 00:00:00
BannerMessage           : 220 FTP Server (ZyWALL USG 20) [::ffff:*server*]

WelcomeMessage          : 230 User *user* logged in

ExitMessage             : 
IsFromCache             : False
IsMutuallyAuthenticated : False
ContentType             : 




PS Z:\> 
为什么不给我一份文件清单? 我用filezilla检查过了-文件夹不是空的。
我可以使用
[System.Net.WebRequestMethods+Ftp]下载特定文件:DownloadFile

WebRequest.GetResponse()
进行远程调用并获取响应详细信息,但其本身没有内容


相反,您需要继续并从响应中读取响应流。

此外,执行尚未完成的脚本需要花费大量时间。您需要阅读并解析响应流($response.GetResponseStream())谢谢-我不知道为什么我忘记了这一点^^