qq_24083561
心情就像下雨天
2019-06-27 22:59

FTPClient本地上传正常,部署后失败

40
  • java

1ftp环境没问题,用户权限没有问题。ftp在linux上安装。

2使用FTPClient上传,本地(win7)上传正常。

3部署到windows server服务器后,上传失败,提示超时。

以下是我的代码


        String ip = "*****";             
        String userName = "***";            
        String passWord = "***";             
        String remoteDirectoryPath = "/var/html";    //上传路径     
        String localFilePath = "C://123.jpg";   //本地文件 
        String remoteFileName = "111.jpg";   //上传后文件

        FTPClient ftpClient = new FTPClient();
        ftpClient.setConnectTimeout(10*1000);
        System.out.println("本地文件路径*****"+localPath);
        try {
            ftpClient.connect(ip,21);
            ftpClient.enterLocalPassiveMode();//本地关闭,部署打开
            boolean isLogin = ftpClient.login(userName, passWord);
            System.out.println("uploadFile 登陆成功 " + isLogin);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.changeWorkingDirectory(remoteDirectoryPath);
            InputStream is = new FileInputStream(new File(localFilePath));
            boolean isStore = ftpClient.storeFile(remoteFileName, is);
            System.out.println("上传成功 " + isStore);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                ftpClient.logout();
                ftpClient.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

8条回答

为你推荐