java中的FTP客户端上传文件有时会显示错误

时间:2015-08-06 05:07:35

标签: java connection ftp-client

HI Friends我正在使用java应用程序将文件存储到服务器中 但是当我上传一些文件时它的节目

org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
QUIT
550 can't access file.

任何人都能告诉我如何解决这个问题吗?

public void uploadtxtFile(String localFileFullName, String fileName, String hostDir)
            throws Exception {
            FTPClient ftpclient= DBConnection.connect();
        File file = new File(localFileFullName);
        if (!(file.isDirectory())) {
            if (file.exists()) {
                FileInputStream input = null;
                 BufferedInputStream bis=null;
               try {
                    input = new FileInputStream(new File(localFileFullName));
                    if (input != null) {

                        hostDir = hostDir.replaceAll("//", "/");
                       logger.info("uploading host dir : " + hostDir);
                     boolean bool =false ;
                       logger.error("Replay of the ftp store file is 1111"+  ftpclient.getReplyCode());
                 try{
                     ftpclient.enterLocalPassiveMode();
                       logger.error("Replay of the ftp store file is 2222"+  ftpclient.getReplyCode());
                   if(  ftpclient.isConnected()){                   
                    //  here server timeout error is get
                       logger.error("here server timeout error is get");//new
                       bis = new BufferedInputStream(input);
                       logger.error("Replay of the ftp store file is 3333"+  ftpclient.getReplyCode());
                       bool =  ftpclient.storeFile(hostDir, bis);

                   }  else{
                       logger.error("here server timeout error is get");//new
                             bis = new BufferedInputStream(input);
                       logger.error("Replay of the ftp store file is 6666"+  ftpclient.getReplyCode());
                       ftpclient.enterLocalPassiveMode();
                       bool =  ftpclient.storeFile(hostDir, bis);
                   }}finally{
                       bis.close();
                    input.close();
                     }

                   logger.error("Replay of the ftp store file is 4444 "+  ftpclient.getReplyCode());
                            if (bool) {
                            logger.info("Success uploading file on host dir :"+hostDir);
                        } else {
                             logger.error("file  not uploaded.");

                        }

                    } else {
                         logger.error("uploading file input null.");
             }
                } catch(Exception ex)
                {
                     logger.error("Error in connection ="+ex);


                }finally {
                 ftpclient.logout();
                     ftpclient.disconnect();

             }

            } else {
                  logger.info("uploading file is not exists.");
            }
        }
    }

并且文件夹的响应也没有显示

1 个答案:

答案 0 :(得分:1)

症状

尝试将文件上传到远程FTP站点时,遇到550错误代码,导致出现类似于以下示例之一的错误消息:

示例1:

STATUS:> Transferring file "/pub/yourfile.txt"...

COMMAND:> SIZE yourfile.txt

550 yourfile.txt: No such file.

STATUS:>   Requested action not taken (e.g., file or directory not found, no access).

COMMAND:> CWD /pub/yourfile.txt

550 /pub/yourfile.txt: No such file or folder.

STATUS:>   Requested action not taken (e.g., file or directory not found, no access).

COMMAND:> STOR yourfile.txt

示例2:

COMMAND:> STOR yourfile.txt

550 Permission Denied.

ERROR:> Requested action not taken (e.g., file or directory not found, no access).

<强>原因

示例1:

在此示例中,远程FTP服务器返回的550代码用于 仅供参考。这不是错误,应该被忽略 由用户。在这种情况下,已经给出了上传命令 但是在上传之前可以启动CuteFTP需要它来确定 是否正在传输的文件已存在于遥控器上 网站作为文件或文件夹。

首先,发送SIZE命令以尝试确定远程站点上是否存在具有相同名称的文件。服务器  以550响应,表示该文件尚不存在 那里。

接下来,发送CWD命令以尝试确定远程站点上是否存在具有相同名称的文件夹。服务器 以550响应,表示该名称的文件夹没有  存在。

最后,给出了STOR命令并开始上传文件。

示例2:

正在尝试上传文件,但远程服务器已拒绝该文件  需要的许可。 550错误代码是不充分的结果  远程FTP服务器上的帐户权限。不会导致错误  由CuteFTP。

解决

示例1:

不适用。在此示例中,远程返回的550代码  FTP服务器仅供参考。这不是一个错误  应该被用户忽略。

示例2:

如果您认为自己的FTP帐户权限或权限 配置不正确,请联系技术支持部门  远程FTP站点或您的Web托管公司寻求帮助。

或者您可以查看FTP "550 Access is denied" Error