【问题标题】:551 Error on output file551 输出文件错误
【发布时间】:2014-07-07 05:44:09
【问题描述】:

我正在使用 apache org.apache.commons.net.ftp.FTPClient 将文件上传到 Apache FTPServer。当我调用 org.apache.commons.net.ftp.FTPClient.storeFile 时,它​​总是以“输出文件上的 551 错误”错误而失败。

这是我的程序

public class FileOperations {

   def ftp (params) {
         def ftp = new FTPClient()
         try {
            ftp.connect(params.host, params.port)
            println ftp.getReplyString()

            int reply = ftp.getReplyCode();

            if(!FTPReply.isPositiveCompletion(reply)) {
               ftp.disconnect();
               System.err.println("FTP server refused connection.");
               return
            }

            boolean successLogin = ftp.login(params.username, params.password)
            println ftp.getReplyString()
            if(!successLogin) {
                println "FTP login unsuccessful "+params.username
                return
            }

            ftp.setFileType(FTPClient.BINARY_FILE_TYPE)
            println ftp.getReplyString()
            ftp.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE)
            println ftp.getReplyString()

            String absoluteFilename=params.file
            def isSuccessful = ftp.storeFile(params.file,new FileInputStream(absoluteFilename))

            println ftp.getReplyString()

            ftp.logout()

    } finally {
        if(ftp.isConnected())
            ftp.disconnect()
    }
}

   static main(args) {
     def operations = new FileOperations();
     def params = [:]
     params.put "host","localhost"
     params.put "port",2121
     params.put "username","test"
     params.put "password","test"
     params.put "file","C:/tmp/sample.txt"

     operations.ftp(params)
   }
}

输出是

220 为新用户准备好服务。

230 用户已登录,继续。

200 命令类型正常。

200 命令模式正常。

551 /C:/tmp/sample.txt: 输出文件出错。

我无法理解此错误的含义。谁能帮我解决这个问题?

【问题讨论】:

    标签: java apache groovy ftp


    【解决方案1】:

    params.put "file","C:/tmp/sample.txt"
    

    您将其用作remote 文件名,它应该是绝对或相对路径名,相对于FTP 用户的FTP 端根目录,可能只是“sample.txt”。 (FTP服务器上没有C:等设备。)

    要读取 本地 文件名,您必须使用完整的路径名,就像现在一样:

    String localFilename = "C:/tmp/sample.txt".
    def isSuccessful = ftp.storeFile(params.file,new FileInputStream(localFilename))
    

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      相关资源
      最近更新 更多