【问题标题】:FTP script not workingFTP 脚本不工作
【发布时间】:2026-02-20 11:15:01
【问题描述】:

我有一个在 Linux 上运行的 FTP 脚本,但它失败了。这是脚本:

/usr/bin/ftp -v -i -n my.ftp.server << cmd
user ftpuser password 
binary 
ls 
<some other commands here>
quit cmd

它返回一个错误:

421 Service not available, remote server has closed connection 
Not connected.

这里奇怪的是,如果我只是在命令行中输入: /usr/bin/ftp my.ftp.server 它要求输入用户名和密码,在我提供它们之后,我就可以连接了!

在 ftp 中,我输入 ls,我可以看到来自 FTP 服务器的文件。 我的脚本有什么问题?

而且,我没有对 FTP 服务器的 putty 访问权限,所以我看不到那里的日志。有什么想法吗?

谢谢!

【问题讨论】:

    标签: linux ftp


    【解决方案1】:

    这是一个正确的 ftp linux 脚本示例。

    #!/bin/sh
    HOST='ftp.server.com'
    USER='user'
    PASSWD='pw'
    FILE='file.txt' #sample file to upload
    
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    put $FILE #sample command
    #some other commands here
    quit
    END_SCRIPT
    exit 0
    

    【讨论】:

    • 我测试了您的脚本,它在我们的开发设置中运行良好,但在我们的生产设置中仍然失败。我注意到在第一行 (ftp -n $host