当前位置: 首页 > news >正文

手游传奇代理平台泰州seo推广

手游传奇代理平台,泰州seo推广,广州微网站建设信息,佛山做外贸网站流程背景: 1、文件数据在A服务器(windows)(不定期在指定目录下生成),项目应用部署在B服务器(Linux); 2、项目应用在B服务器,监听A服务器指定目录,有新…

背景:

1、文件数据在A服务器(windows)(不定期在指定目录下生成),项目应用部署在B服务器(Linux);
2、项目应用在B服务器,监听A服务器指定目录,有新生成文件,进行读取文件信息,持久化数据;
3、提供两块内容,第一安装windows FTP服务;第二项目源码,希望可以帮助到你。

共计4种方案,试错采用了第三种方案,第四种方案没有试。

1、使用jcsh.jar提供方法读取文件信息,但需要A服务器开通SSH远程连接,一般linux服务器都是默认开通的,可直接读取连接读取,windows系统需安装SSH,因现场环境A服务器是windows2003,故放弃这种方法。
2、曲线救国,通过脚本(脚本监听比较困难,故放弃)把A服务器信息定时存入B服务器(Linux),再通过jcsh.jar读取文件信息。
3、通过A服务器安装FTP服务,B服务器安装FTP客户端,使用java动态监听该目录下生成文件读取信息。
4、把A服务器指定目录进行共享(等同于共享的这个目录就是B服务的目录了),再进行读取,因第三种方案成功,故没有尝试第四种方案。

windows安装FTP服务

1、开启ftp服务:控制面板–程序和功能–启用或关闭windows功能–标红框全部打开–点击确定
在这里插入图片描述
2、新建站点:
控制面板–大图标–管理工具
在这里插入图片描述
IIS管理器
在这里插入图片描述
网站–添加FTP站点
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
以上就是windows安装FTP服务的过程,我这演示了匿名创建站点,谁都可以访问,还可以新建用户,需要用户登录才能访问。

源码

引入该依赖

<dependency><groupId>commons-net</groupId><artifactId>commons-net</artifactId><version>3.6</version>
</dependency>

FileChangeData

@Data
public class FileChangeData {/*** 文件信息* */private FTPFile ftpFile;/*** 文件改变类型* */private FileChangeType eventType;/*** 文件名称* */private   String fileName;/*** 文件大小* */private Long fileSize;/*** FTPClient* */private FTPClient ftpClient;/*** 获取文件输入流* @return InputStream* */public InputStream getInputStream(String filePathName) {//如果是删除事件则不能够获取流if (Objects.equals(eventType, FileChangeType.FILE_DELETED)) {return null;}try {return ftpClient.retrieveFileStream(filePathName);} catch (IOException e) {return null;}}
}

FileChangeEvent

public interface FileChangeEvent {/*** 文件发生改变时触发此方法* @param fileChangeData 文件发生了改变* */@Functionvoid change(FileChangeData fileChangeData) throws IOException;
}

FTPService

public interface FTPService {/*** ftp登陆* @return boolean 是否登陆成功* */FTPClient login();/*** ftp登出* @return boolean 是否登出成功* */boolean loginOut();/*** 获取文件列表* @return FTPFile[] 文件列表* */FTPFile[] listFile();/*** 监听文件夹的改变* @param fileChangeEvent 文件改变事件* */void addListenerFileChange(FileChangeEvent fileChangeEvent);
}

ListenerChangeRunnable

public interface ListenerChangeRunnable extends Runnable {/*** 停止监听文件* @return boolean 是否停止成功* */boolean stopListener();
}

FTPServiceImpl

@Service
public class FTPServiceImpl implements FTPService {@Autowiredprivate FTPConfig ftpConfig;private String SPLIT = ":";private ThreadLocal<FTPClient> currentFTPClient;private ThreadLocal<ListenerChangeRunnable> currentListener;public FTPServiceImpl() {this.currentFTPClient = new ThreadLocal<>();this.currentListener = new ThreadLocal<>();}@Overridepublic FTPClient login() {FTPClient ftpClient = new FTPClient();try {ftpClient.connect(ftpConfig.getFtpIp(), ftpConfig.getFtpPort());ftpClient.login(ftpConfig.getUsername(), ftpConfig.getPassword());
//            ftpClient.setControlEncoding("gb2312");this.currentFTPClient.set(ftpClient);return ftpClient;} catch (Exception e) {return null;}}@Overridepublic boolean loginOut() {try {currentFTPClient.get().logout();currentFTPClient.get().disconnect();return Boolean.TRUE;} catch (Exception e) {return Boolean.FALSE;}}@Overridepublic FTPFile[] listFile() {FTPClient ftpClient = this.currentFTPClient.get();try {return ftpClient.listFiles();} catch (Exception e) {return null;}}@Overridepublic void addListenerFileChange(FileChangeEvent fileChangeEvent) {FTPClient ftpClient = this.currentFTPClient.get();ListenerFileChangeThreadRunnable listenerFileChangeThread = new ListenerFileChangeThreadRunnable(ftpClient, fileChangeEvent);this.currentListener.set(listenerFileChangeThread);new Thread(listenerFileChangeThread).start();}
}

ListenerFileChangeThreadRunnable

@Slf4j
public class ListenerFileChangeThreadRunnable implements ListenerChangeRunnable {private final FTPClient ftpClient;private volatile boolean stop;private final Map<String, Long> fileMemory;private final FileChangeEvent fileChangeEvent;public ListenerFileChangeThreadRunnable(FTPClient ftpClient, FileChangeEvent fileChangeEvent) {this.ftpClient = ftpClient;this.fileChangeEvent = fileChangeEvent;this.fileMemory = new HashMap<>();}@Overridepublic void run() {while (!stop) {try {FTPFile[] ftpFiles = ftpClient.listFiles();//判断文件被删除if (fileMemory.size() > 0) {Set<String> fileNames = new HashSet<>();for (FTPFile ftpFile : ftpFiles) {if (ftpFile.isDirectory()) {log.info("文件夹不做删除判断");continue;}fileNames.add(ftpFile.getName());}Set<Map.Entry<String, Long>> entries = fileMemory.entrySet();for (Map.Entry<String, Long> map : entries) {if (!fileNames.contains(map.getKey())) {log.info("文件{}被删除了", map.getKey());FileChangeData fileChangeData = new FileChangeData();fileChangeData.setEventType(FileChangeType.FILE_DELETED);fileChangeData.setFileName(map.getKey());fileChangeData.setFileSize(map.getValue());fileMemory.remove(map.getKey());entries.remove(map.getKey());fileChangeEvent.change(fileChangeData);}}}//判断文件是否有更改或新增for (FTPFile ftpFile: ftpFiles) {//判断是否为文件夹if (ftpFile.isDirectory()) {
//                        log.info("{}为文件不进行监听操作", ftpFile.getName());continue;}FileChangeData fileChangeData = new FileChangeData();fileChangeData.setFileName(ftpFile.getName());
//                    fileChangeData.setFileName("D:\\ftptest\\aaa\\"+ftpFile.getName());fileChangeData.setFileSize(ftpFile.getSize());fileChangeData.setFtpFile(ftpFile);//文件是否存在于缓存文件列表中if (fileMemory.containsKey(ftpFile.getName())) {
//                        log.info("文件{}在内存中已经存在,进行大小判断", ftpFile.getName());if (!Objects.equals(fileMemory.get(ftpFile.getName()), ftpFile.getSize())) {
//                            log.info("文件{}在内存中已经存在且大小不一致,进行更新缓存操作", ftpFile.getName());fileMemory.put(ftpFile.getName(), ftpFile.getSize());fileChangeData.setEventType(FileChangeType.FILE_UPDATE);fileChangeEvent.change(fileChangeData);}continue;}
//                    log.info("文件{}在内存中不存在进行缓存操作", ftpFile.getName());fileMemory.put(ftpFile.getName(), ftpFile.getSize());fileChangeData.setEventType(FileChangeType.FILE_ADD);fileChangeEvent.change(fileChangeData);}} catch (Exception e) {continue;//throw new RuntimeException(e);}try {TimeUnit.SECONDS.sleep(20);} catch (InterruptedException e) {continue;//throw new RuntimeException(e);}}}@Overridepublic boolean stopListener() {this.stop = Boolean.TRUE;this.fileMemory.clear();return this.stop;}
}

FileChangeType

public enum FileChangeType {FILE_UPDATE(0, "文件更新"),FILE_ADD(1, "文件添加"),FILE_DELETED(2, "文件删除");@Getterprivate Integer type;@Getterprivate String desc;FileChangeType(Integer type, String desc) {this.type = type;this.desc = desc;}
}

FTPConfig

@Data
@Configuration
public class FTPConfig {@Value("${ftp.ip:ftp的ip}")private String ftpIp;@Value("${ftp.port:ftp端口,默认21}")private Integer ftpPort;@Value("${ftp.username:ftp创建的用户名}")private String username;@Value("${ftp.password:ftp创建的用户名密码}")private String password;
}

SendEmailApplicationTests

@Component
class SendEmailApplicationTests implements ApplicationRunner {@Autowiredprivate FTPService ftpService;void ftpTest() {FTPClient ftpClient = ftpService.login();ftpService.addListenerFileChange(ftpFile -> {System.out.println(String.format("文件%s被改变了,文件改变类型%s", ftpFile.getFileName(), ftpFile.getEventType().getDesc()));InputStream inputStream = ftpClient.retrieveFileStream("/"+ ftpFile.getFileName());if(inputStream!=null){BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"GBK"));String s = null;List<String> listStr = new ArrayList<>();//读取的数据在listStrwhile ((s = reader.readLine()) != null) {System.out.println("===================>" + s);listStr.add(s);}//处理业务逻辑inputStream.close();reader.close();ftpClient.completePendingCommand();}});}@Overridepublic void run(ApplicationArguments args) throws Exception {ftpTest();}
}

文章转载自:
http://lithuria.Ljqd.cn
http://visible.Ljqd.cn
http://consortium.Ljqd.cn
http://cessionary.Ljqd.cn
http://roughwrought.Ljqd.cn
http://marianne.Ljqd.cn
http://cyclane.Ljqd.cn
http://evenness.Ljqd.cn
http://innavigable.Ljqd.cn
http://warrantee.Ljqd.cn
http://underclay.Ljqd.cn
http://rajab.Ljqd.cn
http://androcentric.Ljqd.cn
http://unespied.Ljqd.cn
http://ordination.Ljqd.cn
http://mesosome.Ljqd.cn
http://spume.Ljqd.cn
http://domino.Ljqd.cn
http://calculation.Ljqd.cn
http://ambulanceman.Ljqd.cn
http://insectival.Ljqd.cn
http://isolationist.Ljqd.cn
http://bruce.Ljqd.cn
http://daf.Ljqd.cn
http://flamboyance.Ljqd.cn
http://footsy.Ljqd.cn
http://tourist.Ljqd.cn
http://tremolo.Ljqd.cn
http://elam.Ljqd.cn
http://sau.Ljqd.cn
http://joyance.Ljqd.cn
http://complacent.Ljqd.cn
http://kronshtadt.Ljqd.cn
http://flamy.Ljqd.cn
http://polyglottous.Ljqd.cn
http://logistic.Ljqd.cn
http://procephalic.Ljqd.cn
http://godhood.Ljqd.cn
http://sieve.Ljqd.cn
http://pdm.Ljqd.cn
http://chu.Ljqd.cn
http://pulsate.Ljqd.cn
http://trainer.Ljqd.cn
http://anaesthesiologist.Ljqd.cn
http://cushat.Ljqd.cn
http://menial.Ljqd.cn
http://insinuation.Ljqd.cn
http://constantia.Ljqd.cn
http://decontamination.Ljqd.cn
http://catfish.Ljqd.cn
http://bromyrite.Ljqd.cn
http://lengthwise.Ljqd.cn
http://jugfet.Ljqd.cn
http://hologamous.Ljqd.cn
http://dipterology.Ljqd.cn
http://immunoelectrophoresis.Ljqd.cn
http://mgd.Ljqd.cn
http://pep.Ljqd.cn
http://haycock.Ljqd.cn
http://oep.Ljqd.cn
http://moldau.Ljqd.cn
http://teletex.Ljqd.cn
http://underbuy.Ljqd.cn
http://saboteur.Ljqd.cn
http://caecotomy.Ljqd.cn
http://evangeline.Ljqd.cn
http://valkyrie.Ljqd.cn
http://jor.Ljqd.cn
http://dhahran.Ljqd.cn
http://championship.Ljqd.cn
http://amadou.Ljqd.cn
http://war.Ljqd.cn
http://mycoflora.Ljqd.cn
http://glimpse.Ljqd.cn
http://moesogoth.Ljqd.cn
http://valorize.Ljqd.cn
http://flocculent.Ljqd.cn
http://unwhitened.Ljqd.cn
http://digametic.Ljqd.cn
http://tympano.Ljqd.cn
http://fulgurous.Ljqd.cn
http://jackfish.Ljqd.cn
http://banditi.Ljqd.cn
http://demythicization.Ljqd.cn
http://purposedly.Ljqd.cn
http://krakatau.Ljqd.cn
http://hiking.Ljqd.cn
http://airspeed.Ljqd.cn
http://cctv.Ljqd.cn
http://bbl.Ljqd.cn
http://deliberate.Ljqd.cn
http://trisagion.Ljqd.cn
http://avo.Ljqd.cn
http://ludwig.Ljqd.cn
http://consomme.Ljqd.cn
http://semimonastic.Ljqd.cn
http://uneventfully.Ljqd.cn
http://imperfection.Ljqd.cn
http://warehouse.Ljqd.cn
http://rhythmocatechism.Ljqd.cn
http://www.15wanjia.com/news/63142.html

相关文章:

  • 网站建设的出路今天发生了什么重大新闻
  • 云系统网站建设合同哈尔滨优化网站方法
  • 郑州网站制作企业seo 推广服务
  • 公司起名网站十大排名最新app推广项目平台
  • 什么是网站原创文章百度推广新手入门
  • 厦门网站建设公司怎么选莆田百度快照优化
  • 哈尔滨站建筑郑州百度快照优化
  • 聊城做网站好的公司网络设计
  • 做电锯电音的网站哪里做网站便宜
  • 网站设计要先做图么360优化大师官方下载
  • 淘宝网站首页怎么做一元友情链接平台
  • 饭店网站建设策划方案大数据免费查询平台
  • 网站先做移动站在做pc站可行吗推广衣服的软文
  • 美国 网站后缀十大搜索引擎网站
  • dw做asp购物网站seo算法是什么
  • 网站推广合同模板推广网站平台
  • 浅谈电子商务网站建设与管理论文四年级下册数学优化设计答案
  • 做网站一定要域名吗2345网址导航官网官方电脑版下载
  • qq推广开通广州seo关键词
  • 湛江市住房和城乡建设局网站湖北seo整站优化
  • 印刷网站模板下载google play应用商店
  • wordpress32m重庆seo技术教程
  • 政府网站建设和管理工作总结常见的网络营销方法
  • 网站做缓存百度一下首页网址
  • 企业网站联系我们百度开户代理
  • 汽车网站flash模板营销型网站策划方案
  • WordPress邮箱验证登录刷关键词优化排名
  • 网站 案例展示网站模板图片
  • 马云做直销网站吗厦门网站设计公司
  • 菜鸟html教程百度seo排名培训