linux - 在 shell 脚本中使用的持久非交互式 FTP session

标签 linux authentication ftp expect non-interactive

我想编写从 Linux 到 Windows FTP 服务器的文件传输的复杂场景(检测新的/更改的文件然后传输),但我找不到支持通过持久性文件发送文件的命令行 ftp 客户端(一次登录)非交互模式 session 。

ssh/scp 使用无密码身份验证不是一个选项,因为我无法访问 Windows FTP 服务器。

例如使用lftp

`lftp -u user,pass -p 21 -e "mput newfile.txt;"` 10.0.0.100 

会将我的文件上传到服务器,但需要对每个请求进行身份验证/握手,这会花费很长时间并严重减慢传输速度。

我想知道是否有一种方法可以验证一次,建立一个持久连接,然后通过这个连接发送文件。 lftp 和其他客户端能够以交互模式执行此操作(连接然后执行多个命令直到退出)。

因此:

  • Linux 上有没有可以在非交互模式下这样运行的 FTP 客户端?
  • 或者,是否有一种方法可以模拟这种行为,通过交互模式编写脚本?也许使用 expectnetcat/telnet 和/或命名管道?

最佳答案

未经测试,但你可以做这样的 Tcl:

package require ftp
set conn [ftp::Open server user pass]
while true {
    after 5000          ;# sleep 5 seconds
    foreach newfile [glob -nocomplain *] {
        puts "sending $newfile"
        ftp::Put $newfile
        file delete $newfile
    }
}

期望是相似的。未经测试:

set timeout -1
spawn lftp -u user,pass server
expect "> "
while true {
    sleep 5
    foreach newfile [glob -nocomplain *] {
        puts "sending $newfile"
        send "put $newfile\r"
        expect "> "
        file delete $newfile
    }
    send "\r"          ;# "hit enter" as a keep-alive
}

关于linux - 在 shell 脚本中使用的持久非交互式 FTP session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30932751/

相关文章:

c - printk 是行缓冲的吗?

html - Azure AD B2C 自定义策略社交按钮顺序

html - 如何从网页在 FileZilla 中执行/打开 FTP/SFTP 站点?

java - org.apache.commons.net.ftp.parser.ParserInitializationException : Unknown parser type: Linux

linux - $(()) 和 expr 有什么区别?

linux - 如何从 SFTP 服务器获取文件并将它们移动到 bash 脚本中的另一个文件夹?

linux - Bash:如何遍历目录结构并执行命令?

javascript - 为什么服务器在发布身份验证信息时说需要 "name"?

javascript - 错误 : FB. 在调用 FB.init() 之前调用了 login()

Python FTP 文件名无效错误