0

我正在尝试从 ftp 位置下载具有特定文件名的每个文件,在其上运行命令然后将其删除。

例如:从“\some\random\ftp\location”下载每个看起来像“*_qwerty.jpeg”的文件,然后对其运行命令。一旦命令完成,删除它。我也需要脚本忽略所有 other.jpeg 文件。

我正在尝试在 Windows CMD 或 Powershell 中执行此操作

有没有人有什么建议?

4

1 回答 1

0

最简单的方法是使用 Ftp.exe 并用参数文件驱动它。使用 mget 下载带有通配符的文件。用 foreach 循环迭代文件并做一些事情。像这样,

<commandfile>
lcd <path-to-local-dir>
open <ftp-site>
<username>
<password>
bin
cd <path-to-remote-dir>
prompt
mget <filename-with-wildcards>
close
bye

在 Powershell 中使用命令文件非常简单:

Ftp -s:<commandfile>
foreach($i in gci <path-to-images>) {
  <do-something> $i
}

您也可以对批处理脚本执行相同的操作(记住在脚本中使用双%,在命令行中使用单%)。

Ftp -s:<commandfile>
for /f "tokens=*" %j in ('dir /b <path-to-images') do <do-something> %j
于 2012-10-12T05:46:27.000 回答