Powershell Get-FTPItem -Path * ... 不起作用

发布于 2025-01-16 19:10:38 字数 824 浏览 2 评论 0原文

我正在编写一个相当小的脚本,旨在从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁我热情 2025-01-23 19:10:38

我最终在 foreach 中使用 Get-FTPChildItem,然后在每个对象上使用 Get-FTPItem。

I ended up using Get-FTPChildItem in a foreach and then using Get-FTPItem on each object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文