SFTP:返回远程目录中的文件数? [英] SFTP: return number of files in remote directory?

查看:900
本文介绍了SFTP:返回远程目录中的文件数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过SFTP将一批文件发送到远程服务器.如果它是本地目录,我可以执行类似ls -l | wc -l的操作来获取文件总数.但是,使用SFTP时,出现错误Can't ls: "/|" not found.

I sent a batch of files to a remote server via SFTP. If it were a local directory I could do something like this ls -l | wc -l to get the total number of files. However, with SFTP, I get an error Can't ls: "/|" not found.

推荐答案

echo ls -l | sftp server | grep -v '^sftp' | wc -l

如果要计算目录中的文件,则目录路径应放在ls -l命令之后,例如

If you want to count the files in a directory the directory path should be put after the ls -l command like

echo ls -l /my/directory/ | sftp server | grep -v '^sftp' | wc -l

这篇关于SFTP:返回远程目录中的文件数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆