我现在有两台Linux的服务器,A、B
A部署这我的工程,我现在要读取B上指定路径的文件,
怎么办,
局域网中的两台服务器,B提供用户名、密码、开放7777端口
我要读temp目录下的*.dat文件,救急!!!

解决方案 »

  1.   

    b转成http上的路径?
     ab服务器是物理上不同么?用ftp协议?
      

  2.   

    通过ftp可以么?
        /**
         * 从远程ftp目录下载文件到本地 <功能详细描述>
         * 
         * @param ftpInfo ftp站点信息
         * @param remoteFileName 远程文件名
         * @param localFilePath 本地文件路径
         * 
         * @return void [返回类型说明]
         * @throws FTPException
         * @throws IOException
         * @throws PortalException
         * @exception throws [违例类型] [违例说明]
         * @see [类、类#方法、类#成员]
         */
        public static void download(FtpSite ftpInfo, String remoteFileName, String localFilePath)
            throws ServerException, IOException, FTPException
        {
            if (log.isDebugEnable())
            {
                log.debug("download start");
            }
            
            FTPClient ftp = null;
            FileOutputStream fos = null;
            
            try
            {
                // 构造ftp客户端信息
                ftp = FtpProxy.getFtpClient(ftpInfo);
                if (null == ftp)
                {
                    throw new ServerException(ResultCode.FTP_CONSTRUCT_FAILD, "ftp实例创建失败!");
                }
                
                // 文件名
                String fileName = getFileName(remoteFileName);
                
                // 本地文件全路径,包括文件名
                String localFileName = localFilePath + fileName;
                
                byte[] buf = null;
                buf = ftp.get(remoteFileName);
                
                // 构造本地文件
                File file = new File(localFileName);
                
                File parents = file.getParentFile();
                
                // 文件的父目录不存在,创建该目录
                if (!parents.exists())
                {
                    parents.mkdirs();
                }
                
                // 本地文件不存在,则创建本地文件
                if (!file.exists())
                {
                    file.createNewFile();
                }
                
                fos = new FileOutputStream(file);
                
                fos.write(buf);
                fos.flush();
                
            }
            finally
            {
                if (null != ftp)
                {
                    ftp.quit();
                }
                
                if (null != fos)
                {
                    fos.close();
                }
            }
        }下载文件到本地
      

  3.   

    使用java.net url 只能读文件,不能读文件夹
    用ftp下载,不能标记哪些文件读过,哪些没读过