Powershell Get-FTPItem -Path * ... 不起作用
我正在编写一个相当小的脚本,旨在从 FTP 文件夹下载所有文件。该脚本是一个 powershell 脚本并使用 PSFTP 模块。 因此,出于测试目的,我在 ftp 文件夹中创建了 3 个随机文件,名为“a”、“b”和“c”。
该脚本的工作方式如下
- 创建 PSCredentials
- 创建 FTP 连接
- 连接到会话
- 从根 ftp 文件夹下载所有文件
因此,除了最后一行之外,所有内容都正常。要获取所有文件,我尝试使用通配符 * 但这会产生一个错误:使用 2 个参数调用“.ctor”时出现
异常整个脚本如下所示:
Import-Module PSFTP
$pass = ConvertTo-SecureString "1234" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('...2', $pass)
Set-FTPConnection -Credentials $cred -Server ... -Session CertFTP -IgnoreCert -UseBinary -KeepAlive
$Session1 = Get-FTPConnection -Session CertFTP
Get-FTPItem -Path * -LocalPath 'C:\Certificats' -Session $Session1
我尝试了相同的操作,但使用 -Path“a”,并且这个正在工作。 因此,我不知道的是:我在语法本身中做错了什么,还是 Get-FTPItem 不支持在 -Path 中使用 * ?
I am working on a fairly small script that aims to download all files from a FTP folder. The script is a powershell script and uses the PSFTP module.
So for test purposes I created 3 randoms files in the ftp folder called "a", "b" and "c".
The script works like this
- Creating PSCredentials
- Creating a FTP connection
- Connecting to session
- Downloading all files from the root ftp folder
So, all is working except the last line. To take all files i try using the wildcard * but this creates an error : Exception calling ".ctor" with 2 argument(s)
The whole script looks like this :
Import-Module PSFTP
$pass = ConvertTo-SecureString "1234" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('...2', $pass)
Set-FTPConnection -Credentials $cred -Server ... -Session CertFTP -IgnoreCert -UseBinary -KeepAlive
$Session1 = Get-FTPConnection -Session CertFTP
Get-FTPItem -Path * -LocalPath 'C:\Certificats' -Session $Session1
I tried the same thing but with -Path "a", and this is working.
Thus, what I don't know is : Am I doing something wrong in the syntax itself, or does Get-FTPItem doesn't support using * in -Path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终在 foreach 中使用 Get-FTPChildItem,然后在每个对象上使用 Get-FTPItem。
I ended up using Get-FTPChildItem in a foreach and then using Get-FTPItem on each object.