Windows服务器从Linux服务器上以FTP形式获取图片
Windows服务器上运行一个获取图片的程序,获取图片采用的是FTP方式;
准备条件:
Linux服务器上创建一个FTP的用户:ftppic
这个账号要有权限才可以,然后编写Windows端代码:
public static boolean downFile(Stringurl,intport, Stringusername,
Stringpassword, StringremotePath, StringfileName,Stringpath
) {
booleansuccess= false;
FTPClientftp= new FTPClient();
intreply;
try{
ftp.connect(url,port);
ftp.login(username,password);
//文件类型为二进制文件
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
reply= ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
returnsuccess;
}
//本地模式
ftp.enterLocalPassiveMode();
ftp.changeWorkingDirectory(remotePath);
FTPFile[]fs= ftp.listFiles();
for(FTPFileff: fs) {
if(ff.getName().equals(fileName)) {
FilelocalFile= new File(path+ff.getName());
OutputStream is= new FileOutputStream(localFile);
ftp.retrieveFile(ff.getName(),is);
is.close();
}
}
ftp.logout();
success= true;
}catch(SocketExceptione) {
e.printStackTrace();
}catch(IOExceptione) {
e.printStackTrace();
}finally{
if(ftp.isConnected()) {
try{
ftp.disconnect();
}catch(IOExceptione) {
e.printStackTrace();
}
}
}
return success;
}
亲测好使。
Windows服务器从Linux服务器上以FTP形式获取图片的更多相关文章
- Windows操作系统远程Linux服务器传输文件方法(以EasyDSS云平台、EasyNVR上传部署为例)
本文转自博客:https://blog.csdn.net/black_3717/article/details/79769406 问题背景: 之前给客户部署我们一款EasyDSS云平台(配合EasyN ...
- 在windows下远程访问linux服务器
在网络性能.安全性.可管理性上,Linux有着其他系统无法比拟的强大优势,而服务器对这些方面要求特别高,因此Linux常常被用来做服务器使用.而当我们需要维护linux服务器的时候,就需要远程访问li ...
- windows 映射samba Linux服务器,输入正确的账号密码却提示“ 指定的网络密码不正确
重启Linux samba服务也没用,重启Linux和windows系统也没用,急!!! 最佳答案 linux中要添加对应的系统用户和samba用户useradd titiansmbpasswd -a ...
- [转]Linux Ubuntu上架设FTP
Linux Ubuntu上架设FTP http://www.blogjava.net/stonestyle/articles/369104.html 操作系统:ubuntu (GNU/Linux) 为 ...
- linux下的ssh工具之,本地上传到linux服务器and Linux服务器文件另存为本地。非sftp工具。
首先,当你只有一个ssh工具可以连接linux,但你有想把文件在 linux 和windows(本地)直接的切换.其实可以的: 本文参考 1.将本地的文件,放到ssh远程的linux服务器上: 首先要 ...
- Windows定时任务下载linux服务器批量文件到本地
编写批文件 1.1 编写main.bat文件 E: cd logs ftp -n -s:"E:\logs\mget.bat" 1.2 编写mget.bat文件 open ip地址 ...
- 同步windows时间到linux服务器
输入date -R 查看系统时间 输入命令 ntpdate time.windows.com 同步windows时间到linux
- Linux Ubuntu上架设FTP
操作系统:ubuntu (GNU/Linux) 为了在机子上架设ftp服务器,我们需要安装ftp服务器软件.Linux下具有代表性的ftp服务器软件有Wu-FTP,ProFTP和Vsftp.Wu-FT ...
- 云服务器 ECS Linux 服务器修改时区的两种方式
在云服务器 ECS Linux 系统中,以 Centos6.5 为例,可以通过如下两种方式,修改系统时区: 可以使用命令 tzselect,修改时区.操作示例: [root@localhost ~]# ...
随机推荐
- IOS-<input>表单元素只能读,设置readonly时光标仍然可见的解决办
在HTML中,如果把一个<input>的readonly属性设置为"readonly",表示这个表单元素不能编辑. 但是,鼠标点击之后,这个表单元素还是有光标存在的. ...
- WinRT 开发:在 MVVM 模式中,关于绑定的几处技巧
以下会提到三个绑定的技巧,分别是 在 ListView 中为 ListViewItem 的 MenuFlyout 绑定 Command: 在 ListView 的 事件中绑定所选择项目,即其 Sele ...
- ionic build Android错误记录 error in opening zip file
0.写在前头 运行 :cordova requirements Requirements check results for android: Java JDK: installed 1.8.0 An ...
- ElasticSearch常用结构化搜索
最近,需要用到ES的一些常用的结构化搜索命令,因此,看了一些官方的文档,学习了一下.结构化查询指的是查询那些具有内在结构的数据,比如日期.时间.数字都是结构化的. 它们都有精确的格式,我们可以对这些数 ...
- HDU3625 Examining the Rooms
@(HDU)[Stirling數] Problem Description A murder happened in the hotel. As the best detective in the t ...
- SQL 列转行与行转列
假设有张学生成绩表(tb)如下:Name Subject Result张三 语文 74张三 数学 83张三 物理 93李四 语文 74李四 数学 84李四 物理 94*/ -------------- ...
- ios 联网 在mac机器上进行抓包
Remote Virtual Interface在使用Mac抓取iPhone数据包中介绍了两种方式在Mac电脑上抓取iPhone上的数据包,一是使用Mac的网络共享功能将Mac的网络通过WiFi共享给 ...
- Android自定义xml解析
<?xml version="1.0" encoding="utf-8"?> <resources> <Users> < ...
- sublime的tab和spaces空格切换的坑
python是严格要求对齐或者叫缩进的: 使用sublime对python进行编程时,可以使用tab或者空格,但是不能混用.特别是从外面把代码拷贝进sublime的时候,更要注意是否一致. 简单介绍一 ...
- 3D投影
3D投影方式的几大种类: 1.快门式 主动快门式即时分式,不过我们通常用前面的叫法,快门式3D眼镜(3D Shutter Glasses,也称作LC shutter glassesor active ...