Windows服务器上运行一个获取图片的程序,获取图片采用的是FTP方式;

准备条件:

Linux服务器上创建一个FTP的用户:ftppic

这个账号要有权限才可以,然后编写Windows端代码:

  1. public static boolean downFile(Stringurl,intport, Stringusername,
  2. Stringpassword, StringremotePath, StringfileName,Stringpath
  3. ) {
  4. booleansuccess= false;
  5. FTPClientftp= new FTPClient();
  6. intreply;
  7. try{
  8. ftp.connect(url,port);
  9. ftp.login(username,password);
  10. //文件类型为二进制文件
  11. ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
  12. reply= ftp.getReplyCode();
  13. if(!FTPReply.isPositiveCompletion(reply)) {
  14. ftp.disconnect();
  15. returnsuccess;
  16. }
  17. //本地模式
  18. ftp.enterLocalPassiveMode();
  19. ftp.changeWorkingDirectory(remotePath);
  20. FTPFile[]fs= ftp.listFiles();
  21. for(FTPFileff: fs) {
  22. if(ff.getName().equals(fileName)) {
  23. FilelocalFile= new File(path+ff.getName());
  24. OutputStream is= new FileOutputStream(localFile);
  25. ftp.retrieveFile(ff.getName(),is);
  26. is.close();
  27. }
  28. }
  29. ftp.logout();
  30. success= true;
  31. }catch(SocketExceptione) {
  32. e.printStackTrace();
  33. }catch(IOExceptione) {
  34. e.printStackTrace();
  35. }finally{
  36. if(ftp.isConnected()) {
  37. try{
  38. ftp.disconnect();
  39. }catch(IOExceptione) {
  40. e.printStackTrace();
  41. }
  42. }
  43. }
  44. return success;
  45. }

亲测好使。

Windows服务器从Linux服务器上以FTP形式获取图片的更多相关文章

  1. Windows操作系统远程Linux服务器传输文件方法(以EasyDSS云平台、EasyNVR上传部署为例)

    本文转自博客:https://blog.csdn.net/black_3717/article/details/79769406 问题背景: 之前给客户部署我们一款EasyDSS云平台(配合EasyN ...

  2. 在windows下远程访问linux服务器

    在网络性能.安全性.可管理性上,Linux有着其他系统无法比拟的强大优势,而服务器对这些方面要求特别高,因此Linux常常被用来做服务器使用.而当我们需要维护linux服务器的时候,就需要远程访问li ...

  3. windows 映射samba Linux服务器,输入正确的账号密码却提示“ 指定的网络密码不正确

    重启Linux samba服务也没用,重启Linux和windows系统也没用,急!!! 最佳答案 linux中要添加对应的系统用户和samba用户useradd titiansmbpasswd -a ...

  4. [转]Linux Ubuntu上架设FTP

    Linux Ubuntu上架设FTP http://www.blogjava.net/stonestyle/articles/369104.html 操作系统:ubuntu (GNU/Linux) 为 ...

  5. linux下的ssh工具之,本地上传到linux服务器and Linux服务器文件另存为本地。非sftp工具。

    首先,当你只有一个ssh工具可以连接linux,但你有想把文件在 linux 和windows(本地)直接的切换.其实可以的: 本文参考 1.将本地的文件,放到ssh远程的linux服务器上: 首先要 ...

  6. Windows定时任务下载linux服务器批量文件到本地

    编写批文件 1.1 编写main.bat文件 E: cd logs ftp -n -s:"E:\logs\mget.bat" 1.2 编写mget.bat文件 open ip地址 ...

  7. 同步windows时间到linux服务器

    输入date -R 查看系统时间 输入命令  ntpdate time.windows.com 同步windows时间到linux

  8. Linux Ubuntu上架设FTP

    操作系统:ubuntu (GNU/Linux) 为了在机子上架设ftp服务器,我们需要安装ftp服务器软件.Linux下具有代表性的ftp服务器软件有Wu-FTP,ProFTP和Vsftp.Wu-FT ...

  9. 云服务器 ECS Linux 服务器修改时区的两种方式

    在云服务器 ECS Linux 系统中,以 Centos6.5 为例,可以通过如下两种方式,修改系统时区: 可以使用命令 tzselect,修改时区.操作示例: [root@localhost ~]# ...

随机推荐

  1. AC日记——太空飞行计划 洛谷 P2762

    题目背景 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的 ...

  2. 通过jQuery Ajax提交表单数据时同时上传附件

    1.使用场景:需要使用ajax提交表单,但是提交的表单里含有附件上传 2.代码实现方式: <!-- HTML代码 --> <form method="post" ...

  3. python3 - pop 接收邮件/ smtp 发送邮件

    以下通过python3 实现接收和发送邮件,网上相关说明文档很多.请自己查阅,这里只写入代码, # 实例:通过poplib 模块接收指定账号的邮件并进行解码处理,结果可视化. #!/opt/pytho ...

  4. FMDB使用SQLite事务Save Point

    FMDB使用SQLite事务Save Point   在SQLite中,事务提供了批量处理,批量撤销的功能.当批量操作中有一步无法完成操作,就会把执行过的语句都撤销,恢复到撤销前的状态.但是由于SQL ...

  5. k8s之Service资源

    1.Service概述 service是kubernetes中最核心的资源对象之一,service和pod之间是通过Label串起来,相同的Service的pod的Label是一样的.同一个servi ...

  6. CodeForces - 600F Edge coloring of bipartite graph

    Discription You are given an undirected bipartite graph without multiple edges. You should paint the ...

  7. redis常用命令与使用分析

    redis-cli的使用 连接服务器 redis-cli -h 127.0.0.1 -p 6392  -a 123456 set操作 语法 sadd key [members.......]      ...

  8. 配置laravel的nginx站点

    server{}配置 server{ #端口配置 listen 80; #域名配置 server_name laravel.cc; index index.php index.html index.h ...

  9. SilverLight:基础控件使用(6)-Slider控件

    ylbtech-SilverLight-Basic-Control:基础控件使用(6)-Slider控件 Slider 控件 Slider 控件的 ValueChanged 事件 1.A,返回顶部 S ...

  10. 解决Sophos UTM 9防火墙上的“根分区填满”问题

    Resolving 'Root Partition Is Filling Up' Issue on Sophos UTM Firewall 收到“Sophos UTM 9”防火墻的“根分區填满”问题的 ...