FtpClient storeFile总是返回False [英] FtpClient storeFile always return False

查看:942
本文介绍了FtpClient storeFile总是返回False的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请弄清楚这一点。代码正常运行,没有任何异常。

Please figure this out. The code runs properly without any exception.

        FTPClient ftp = new FTPClient();
        ftp.connect(server);
        if(!ftp.login(username, password))
        {
            ftp.logout();
            return false;
        }
        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply))
        {
            ftp.disconnect();
            return false;
        }
        InputStream in = new FileInputStream(localfile);
        ftp.setFileType(ftp.BINARY_FILE_TYPE, ftp.BINARY_FILE_TYPE);
        ftp.setFileTransferMode(ftp.BINARY_FILE_TYPE);
        Store = ftp.storeFile(destinationfile, in);
        in.close();
        ftp.logout();
        ftp.disconnect();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
        return false;
    }
    return Store;

Buttttttttt

Buttttttttt

return语句总是返回false并且文件未上载到服务器上。有人请帮助。

return statement always return false and the file is not uploaded on the server. Some one please help on this.

您的信息,
1)我在办公室网络。 --->我们需要添加任何代理吗?

For your information, 1) i am in an office network. ---> do we need to add any proxies?

          File file = new File("C:\\Users\\sg0214273\\Desktop\\seagate\\seagate.txt");
          FileInputStream input = new FileInputStream(file);
          client.setFileType(FTP.BINARY_FILE_TYPE);
          if (!client.storeFile(file.getName(), input)) {
            System.out.println("upload failed!");
          } 
          reply = client.getReplyCode();

            if(!FTPReply.isPositiveCompletion(reply)) {
                System.out.println("upload failed!");
            }



         Login success...
         230 User ******** logged in.
         upload failed!-----> is form boolean return value of storefile 
         upload failed!---------> is from replycode...
         Logout from FTP server...

请帮助

推荐答案

通过调用 FtpClient#getReplyCode()。从那个页面(我的重点):

The exact failure message can be found by calling FtpClient#getReplyCode(). From that page (my emphasis):


连接后立即是你需要检查
回复代码的唯一实时时间(因为connect属于void类型。
的约定FTPClient中的所有FTP命令方法都是这样的,它们要么
返回一个布尔值或一些其他值。布尔方法在从FTP服务器成功完成回复时返回
true,在
时返回false,导致错误条件或失败。
返回除布尔值以外的值的方法返回包含FTP命令生成的
更高级别数据的值,如果回复
导致错误条件或失败,则返回null。 如果您想要访问导致成功或失败的
确切的FTP回复代码,您必须在成功或失败后调用
getReplyCode。

要查看返回代码的含义,您可以看到维基百科:FTP服务器返回码列表

To see what a return code means, you can see Wikipedia: List of FTP server return codes.

这篇关于FtpClient storeFile总是返回False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆