在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"
!