sftp获取服务端目录下文件列表

在ftp命令中,获取远程服务端的文件列表直接通过ls命令即可将服务器中文件列表存入本地

ls[remote-dir][local-file]:显示远程目录remote-dir,并存入本地文件local-file

在sftp中就没有命令可用,只能自己想办法。

具体命令如下:

expect > /data1/tmp/file_list.txt <<-!
set timeout 99999
spawn sftp bass@127.0.0.1
expect "Authorized only. All activity will be monitored and reported.bass@127.0.0.1's password:"
send "password\n"
expect "sftp>"
send "cd  /data1/bin\n"
expect "sftp>"
send "ls -tlr\n"
expect "sftp>"
send "exit\n"
!

 

posted @ 2020-03-10 15:37  lxpaopao  阅读(1073)  评论(0编辑  收藏  举报