【问题标题】:Using grep and ls in FTP client?在 FTP 客户端中使用 grep 和 ls?
【发布时间】:2010-12-09 18:28:44
【问题描述】:

如何在 FTP 客户端中使用 grepls...

我的意思是,如果我想找到一些我可以使用的特定文件:

 ls -l | grep pattern

【问题讨论】:

  • 您需要再解释一下这个问题吗?什么 FTP 客户端?
  • @Vijay:我的意思是我想要列出 ftp 服务器上的文件并使用 grep 过滤结果的功能。我在 Debian Lenny 下使用 ftp 命令。

标签: ftp grep ls


【解决方案1】:

使用通常的 Unix 命令行交互式 ftp,一种方法是:

Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir . foobar
output to local-file: foobar [anpqy?]? y
500 Unknown command
227 Entering Passive Mode (62,149,140,15,195,159)
150 Accepted data connection
 11966       5.26 KB/s 
226-Options: -a -l 
226 156 matches total
ftp> !grep con foobar
-rwxr-xr-x    1 11050207   users          911007 Sep 13  2007 accu_pyconc.pdf
-rwxr-xr-x    1 11050207   users         9805405 Mar 25  2009 pycon_abst.pdf

即,首先将 dir 结果放入本地文件,然后在本地运行 grep。顺便说一句,这可以让您在支付一次dir 数据传输费用后运行多个 grep;-)。

【讨论】:

  • 谢谢。这是否意味着没有 ftp 客户端支持 shell 之类的功能,例如管道甚至内置调用(我的意思是没有'!')到其他命令,如 grep...
  • @jcyang,不在 Unix &c 附带的股票 ftp 交互式命令行客户端中,但您当然可以编写不同的客户端:SO 是关于开发软件,而不是关于使用现有程序(参见that 的 serverfault 和超级用户),对吗?因此,以您选择的语言获取起始源代码,例如在example-code.com/python/pythonftp.asp 上为 python 提供大量示例,并编写代码以创建一个具有您认为它应该具有的功能的新客户端程序!
【解决方案2】:

lftp 可以,完全按照您输入的方式。

【讨论】:

  • 谢谢。这正是我想要的。
【解决方案3】:

在 Windows 上,您可以使用 WinSCP scripting 为任何协议执行此操作,包括 FTP:

winscp.com /command ^
    "open ftp://username:password@example.com" ^
    "ls /path/*.txt" ^
    "exit"

参考资料:
https://winscp.net/eng/docs/scripting
https://winscp.net/eng/docs/scriptcommand_ls

【讨论】:

    【解决方案4】:

    您可以将 sftp 文件夹挂载到您有权使用 grep 或任何工具的主机上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2011-08-09
      相关资源
      最近更新 更多