ftp获取本地路径怎么写

1.怎么获取ftp的路径

问一下,你是想做ftp上传下载么?首先你需要安装一个ftp服务端程序,启动起来,然后下载一个ftp客户端程序,测试能不能连接,首先这一块儿需要测试通过。

代码ftp上传下载 2.1 上传代码: import java.io.File; import java.io.FileInputStream; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; public class test { private FTPClient ftp; /** * * @param path 上传到ftp服务器哪个路径下 * @param addr 地址 * @param port 端口号 * @param username 用户名 * @param password 密码 * @return * @throws Exception */ private boolean connect(String path,String addr,int port,String username,String password) throws Exception { boolean result = false; ftp = new FTPClient(); int reply; ftp.connect(addr,port); ftp.login(username,password); ftp.setFileType(FTPClient.BINARY_FILE_TYPE); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); return result; } ftp.(path); result = true; return result; } /** * * @param file 上传的文件或文件夹 * @throws Exception */ private void upload(File file) throws Exception{ if(file.isDirectory()){ ftp.makeDirectory(file.getName()); ftp.(file.getName()); String[] files = file.list(); for (int i = 0; i < files.length; i++) { File file1 = new File(file.getPath()+"\\"+files[i] ); if(file1.isDirectory()){ upload(file1); ftp.(); }else{ File file2 = new File(file.getPath()+"\\"+files[i]); FileInputStream input = new FileInputStream(file2); ftp.storeFile(file2.getName(), input); input.close(); } } }else{ File file2 = new File(file.getPath()); FileInputStream input = new FileInputStream(file2); ftp.storeFile(file2.getName(), input); input.close(); } } public static void main(String[] args) throws Exception{ test t = new test(); t.connect("", "localhost", 21, "yhh", "yhhazr"); File file = new File("e:\\uploadify"); t.upload(file); } } 2.2 下载代码 这里没有用到filter,如果用filter就可以过滤想要的文件。 public class Ftp { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Ftp ftp = new Ftp(); String hostname = ""; Integer port = 21; String username = "username"; String password = "password"; String remote = "/c.txt"; String local = "/home/tin/LeonChen/FTP/"; try { ftp.connect(hostname, port, username, password); System.out.println("接收状态:"+ftp.download(remote, local)); ftp.disconnect(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private FTPClient ftpClient = new FTPClient(); /* * * 连接到FTP服务器 * * @param hostname 主机名 * * @param port 端口 * * @param username 用户名 * * @param password 密码 * * @return 是否连接成功 * * @throws IOException */ private boolean connect(String hostname, int port, String username, String password) throws IOException { ftpClient.connect(hostname, port); ftpClient.setControlEncoding("UTF-8"); if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { if (ftpClient.login(username, password)) { return true; } } disconnect(); return false; } /* * 从FTP服务器上下载文件,支持断点续传,上传百分比汇报 * * @param remote 远程文件路径 * * @param local 本地文件路径 * * @return 上传的状态 * * @throws IOException */ public DownloadStatus download(String remote, String local) throws IOException { // 设置被动模式 ftpClient.enterLocalPassiveMode(); // 设置以二进制方式传输 ftpClient.setFileType(FTP.BINARY_FILE_TYPE); DownloadStatus result; // 检查远程文件是否存在 FTPFile[] files = ftpClient.listFiles(new String(remote .getBytes("UTF-8"), "iso-8859-1")); if (files.length != 1) { System.out.println("远程文件不存在"); return DownloadStatus.Remote_File_Noexist; } long lRemoteSize = files[0].getSize(); String fildName = files[0].getName(); // 本地存在文件,进行断点下载 File f = new File(local+fildName); if (f.exists()) { long localSize = f.length(); if (localSize >= lRemoteSize) { System.out.println("本地文件大于远程文件,下载中止"); return DownloadStatus.Local_Bigger_Remote; } // 进行断点续传,并记录状态 FileOutputStream out = new FileOutputStream(f, true); ftpClient.setRestartOffset(localSize); InputStream in = ftpClient.retrieveFileStream(new String(remote.getBytes("UTF-8"), "iso-8859-1")); byte[] bytes = new byte[1024]; long step = lRemoteSize / 100; long process = localSize / step; int c; while ((c = in.read(bytes)) != -1) { out.write(bytes, 0, c); localSize += c; long nowProcess = localSize / step; if (nowProcess > process) { process = nowProcess; if (process % 10 == 0) 。

2.怎么获取ftp的路径

问一下,你是想做ftp上传下载么?首先你需要安装一个ftp服务端程序,启动起来,然后下载一个ftp客户端程序,测试能不能连接,首先这一块儿需要测试通过。

代码ftp上传下载 2.1 上传代码: import java.io.File; import java.io.FileInputStream; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; public class test { private FTPClient ftp; /** * * @param path 上传到ftp服务器哪个路径下 * @param addr 地址 * @param port 端口号 * @param username 用户名 * @param password 密码 * @return * @throws Exception */ private boolean connect(String path,String addr,int port,String username,String password) throws Exception { boolean result = false; ftp = new FTPClient(); int reply; ftp.connect(addr,port); ftp.login(username,password); ftp.setFileType(FTPClient.BINARY_FILE_TYPE); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); return result; } ftp.(path); result = true; return result; } /** * * @param file 上传的文件或文件夹 * @throws Exception */ private void upload(File file) throws Exception{ if(file.isDirectory()){ ftp.makeDirectory(file.getName()); ftp.(file.getName()); String[] files = file.list(); for (int i = 0; i < files.length; i++) { File file1 = new File(file.getPath()+"\\"+files[i] ); if(file1.isDirectory()){ upload(file1); ftp.(); }else{ File file2 = new File(file.getPath()+"\\"+files[i]); FileInputStream input = new FileInputStream(file2); ftp.storeFile(file2.getName(), input); input.close(); } } }else{ File file2 = new File(file.getPath()); FileInputStream input = new FileInputStream(file2); ftp.storeFile(file2.getName(), input); input.close(); } } public static void main(String[] args) throws Exception{ test t = new test(); t.connect("", "localhost", 21, "yhh", "yhhazr"); File file = new File("e:\\uploadify"); t.upload(file); } } 2.2 下载代码 这里没有用到filter,如果用filter就可以过滤想要的文件。 public class Ftp { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Ftp ftp = new Ftp(); String hostname = ""; Integer port = 21; String username = "username"; String password = "password"; String remote = "/c.txt"; String local = "/home/tin/LeonChen/FTP/"; try { ftp.connect(hostname, port, username, password); System.out.println("接收状态:"+ftp.download(remote, local)); ftp.disconnect(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private FTPClient ftpClient = new FTPClient(); /* * * 连接到FTP服务器 * * @param hostname 主机名 * * @param port 端口 * * @param username 用户名 * * @param password 密码 * * @return 是否连接成功 * * @throws IOException */ private boolean connect(String hostname, int port, String username, String password) throws IOException { ftpClient.connect(hostname, port); ftpClient.setControlEncoding("UTF-8"); if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { if (ftpClient.login(username, password)) { return true; } } disconnect(); return false; } /* * 从FTP服务器上下载文件,支持断点续传,上传百分比汇报 * * @param remote 远程文件路径 * * @param local 本地文件路径 * * @return 上传的状态 * * @throws IOException */ public DownloadStatus download(String remote, String local) throws IOException { // 设置被动模式 ftpClient.enterLocalPassiveMode(); // 设置以二进制方式传输 ftpClient.setFileType(FTP.BINARY_FILE_TYPE); DownloadStatus result; // 检查远程文件是否存在 FTPFile[] files = ftpClient.listFiles(new String(remote .getBytes("UTF-8"), "iso-8859-1")); if (files.length != 1) { System.out.println("远程文件不存在"); return DownloadStatus.Remote_File_Noexist; } long lRemoteSize = files[0].getSize(); String fildName = files[0].getName(); // 本地存在文件,进行断点下载 File f = new File(local+fildName); if (f.exists()) { long localSize = f.length(); if (localSize >= lRemoteSize) { System.out.println("本地文件大于远程文件,下载中止"); return DownloadStatus.Local_Bigger_Remote; } // 进行断点续传,并记录状态 FileOutputStream out = new FileOutputStream(f, true); ftpClient.setRestartOffset(localSize); InputStream in = ftpClient.retrieveFileStream(new String(remote.getBytes("UTF-8"), "iso-8859-1")); byte[] bytes = new byte[1024]; long step = lRemoteSize / 100; long process = localSize / step; int c; while ((c = in.read(bytes)) != -1) { out.write(bytes, 0, c); localSize += c; long nowProcess = localSize / step; if (nowProcess > process) { process = nowProcess; if (process % 10 == 0) System.out.println("下载进度:" + process); // TODO 更新文件下载进。

3.怎么用ftp 取文件 命令

熟悉并灵应用FTP内部命令便使用者并收事半功倍效

FTP命令行格式:ftp -v -d -i -n -g [主机名]其

-v显示远程服务器所响应信息;

-n限制ftp自登录即使用;

.n etrc文件;

-d使用调试式;

-g取消全局文件名

ftp使用内部命令(括号表示选项):

1.![cmd[args]]:本机执行交互shellexitftp环境:!ls*.zip.

2.$ macro-ame[args]:执行宏定义macro-name.

3.account[password]:提供登录远程系统功访问系统资源所需补充口令

4.append local-file[remote-file]:本文件追加远程系统主机若未指定远程系统文件名则使用本文件名

5.ascii:使用ascii类型传输式

6.bell:每命令执行完毕计算机响铃

7.bin:使用二进制文件传输式

8.bye:退ftp程

9.case:使用mget远程主机文件名写转写字母

10.cd remote-dir:进入远程主机目录

11.cdup:进入远程主机目录父目录

12.chmod mode file-name:远程主机文件file-name存取式设置mode:chmod 777 a.out

13.close:断与远程服务器ftp(与open应)

14.cr:使用asscii式传输文件车换行转换行

4.ftp中使用get后,文件位于本地哪里

我给你写个具体的.

ftp> ftp 128.1.99.200 这个是连接地址

ftp>; 这里提示输入用户名

ftp>;密码

ftp>ascii 以什么样的文件格式传送 这个是2进制文件形式

ftp>lcd c:/aaa 这里就是定义你要get的文件放在本地的哪个地方 这里是放在c盘 aaa文件下

ftp>get 路径名 你要get的文件路径

你的问题就是lcd那步

ftp获取本地路径怎么写

转载请注明出处育才学习网 » ftp获取本地路径怎么写

知识

divcss里文字上下滚动的代码怎么写

阅读(272)

本文主要为您介绍divcss里文字上下滚动的代码怎么写,内容包括div中的文字滚动效果的代码怎么写,不要jsp的,就直接用属性或者更,div中有一行文字,怎么实现部分文字上下滚动效果,html中上下滚动的文字代码,举例。<HTML> <HEAD> <META http-eq

知识

css初始化代码怎么写

阅读(224)

本文主要为您介绍css初始化代码怎么写,内容包括CSS初始化的代码怎么写,CSS初始化的代码怎么写,css初始化代码怎么用。1. 最耗资源的,最简单的* { padding: 0; margin: 0; border: 0; } 2. 选择性初始化举例(综合)

知识

小学生的梦想卡怎么写

阅读(430)

本文主要为您介绍小学生的梦想卡怎么写,内容包括梦想卡的内容怎么写,小学三年级梦想卡怎么写,小学生心愿卡内容写什么。1,又到了路口。未来总是有方向,但是却还没有头绪。我们迎来一个个新的开始,又和开始说了再见,时光荏苒,又是一个秋。我们带

知识

三年级日记一则怎么写

阅读(250)

本文主要为您介绍三年级日记一则怎么写,内容包括小学生三年级曰记一篇怎么写,三年级曰记作文怎么写,三年级的日记怎么写。三年级记事日记:今天,妈妈教我学洗衣服。一开始我以为很容易,妈妈说:“我们先接一盆水,然后再放一点洗衣粉,用手把洗衣粉搅

知识

护士长优秀事迹怎么写

阅读(228)

本文主要为您介绍护士长优秀事迹怎么写,内容包括优秀护士事迹怎么写,评选优秀护士主要先进事迹怎么写,护士主要事迹怎么写。原发布者:Susce优秀护士先进事迹材料:优质护理服务之她行在护理和护理管理工作中,刘建英同志爱岗敬业,本着艰苦奋斗和

知识

java代码目录结构怎么写

阅读(227)

本文主要为您介绍java代码目录结构怎么写,内容包括使用java读取指定路径的目录结构;帮我把具体的代码,例子写出来,,java项目代码结构说明书怎么写,Java实现的多层目录结构呢。Node:目录节点,具备节点属性信息 NodeStore:平面目录节点持久化接口

知识

树懒怎么写英语怎么写

阅读(206)

本文主要为您介绍树懒怎么写英语怎么写,内容包括树懒英文怎么写,树懒英文怎么读,求疯狂动物城树懒那段英语台词,在线等。Nice tosee youtoo.Flash,Id love you to meet my friend.Darling,I seem

知识

宁愿的英语单词怎么写

阅读(222)

本文主要为您介绍宁愿的英语单词怎么写,内容包括宁的英文怎么写,单词的英文怎么写,1至100的英文怎么写。单词的英文表示为:word2、word的英式发音为[wɜ:d],美式发音为[wɜ:rd] ,意思有:单词;话语;诺言;消息,措辞,用词;

知识

拧螺丝的拼音怎么写的

阅读(279)

本文主要为您介绍拧螺丝的拼音怎么写的,内容包括拧螺丝的拧怎么读,拧脑袋的读音拧螺丝的读音拧开的读音拧毛巾的读音,拧开螺丝的读音。拧螺丝的拧的拼音是nǐng,拧的意思是控制住物体并向里转或向外转。拧拼 音 :nǐng níng nìng 部 首:扌笔

知识

co.ltd分公司怎么写

阅读(288)

本文主要为您介绍co.ltd分公司怎么写,内容包括总公司的英文缩写为CO.LTD,分公司应该如何写,公司名称中,Co.,Ltd.是什么的缩写,请列举co.,ltd的几种正确写法。Co. LTD 是 Company Limited 即“有限责任公司”的缩写,并非“总公司”。总公司一

知识

construct的名词怎么写

阅读(1005)

本文主要为您介绍construct的名词怎么写,内容包括他会将这个词的名词,动词,形容词,副词的形式归在一起比如查,assure的名词怎么写,英语单词“建设”怎么写。collection [kəlekʃən] n. 收藏品,收集物 例句: Is the collection going to be

知识

ong字怎么写

阅读(288)

本文主要为您介绍ong字怎么写,内容包括“ong”拼音怎么读,读音为ong的字,押ONG韵的字。只有一个,如下图:

知识

笔记本上的date怎么写

阅读(413)

本文主要为您介绍笔记本上的date怎么写,内容包括请问笔记本上的date//怎么填,第一杠杠前面填日还是月,请问笔记本上的date//怎么填,第一杠杠前面填日还是月,笔记本上的NO.和Date是什么意思。NO.指的是编号,Date指的是日期。笔记本电脑型号后

知识

swift单例模式怎么写

阅读(211)

本文主要为您介绍swift单例模式怎么写,内容包括在swift中,单例模式与定义的全局变量有什么区别,如何写一个简单的单例模式,单例模式代码怎么写。基本的实现思路:单例的实现主要是通过以下两个步骤:将该类的构造方法定义为私有方法,这样其他处

知识

dw如何获取代码怎么写

阅读(231)

本文主要为您介绍dw如何获取代码怎么写,内容包括如何用DW获取网页上需要的html代码,如何用dw获取网页上需要的html代码,用dw编写代码如何查看。JS代码如下:<script language="javascript">var mydate = new Date();var myy

知识

程序怎么写数据库相对路径

阅读(287)

本文主要为您介绍程序怎么写数据库相对路径,内容包括c#程序怎么写数据库相对路径,winform中怎样写数据库的相对路径,c#程序怎么写数据库相对路径。这个需要的超链接指向文件在服务器的绝对路径,即下面获取到的文件的编译路径 :/*** 获取当前

知识

androidurl文件路径怎么写

阅读(287)

本文主要为您介绍androidurl文件路径怎么写,内容包括android文件路径怎么写,访问androidassets下的文件路径要怎么写,求教android相对路径的写法。public static void writeFileData(String fileName, String message){tr

知识

项目实施路径怎么写

阅读(363)

本文主要为您介绍项目实施路径怎么写,内容包括什么是实施路径,项目实施方案怎么写,项目建设实施方案怎么写。最低0.27元/天开通百度文库会员,可在文库查看完整内容>原发布者:WL课件库项目实施方案技术方案、项目实施方案某某广告有限公司是由

知识

idea路径怎么写

阅读(206)

本文主要为您介绍idea路径怎么写,内容包括idea中如何使用resource的文件的相对路径怎么写,idea中无效的日志路径怎么解决,IntelliJIDEA中怎么查看方法说明。写代码时用Alt-Insert(Code|Generate…)可以创建类里面任何字段的getter与setter

知识

jsp保存文件路径怎么写

阅读(248)

本文主要为您介绍jsp保存文件路径怎么写,内容包括jsp如何向本地路径下写文件,jsp文件应该写在什么路径下,以及该路径的配置,jsp如何向本地路径下写文件。如果是本路径下的IMG,不需要引入相对路径,因为默认就会在当前路径下找相应的图片。举例

知识

微信小程序分享路径怎么写

阅读(259)

本文主要为您介绍微信小程序分享路径怎么写,内容包括怎么把小程序分享直接做成链接,微信小程序绑定公众号自定义菜单,提示请输入小程序路径,微信小程序分享活动给朋友,怎么可以提取活动面页的链接大神们救。首先打开js软件新建一个小程序的

知识

js获取页面代码怎么写

阅读(309)

本文主要为您介绍js获取页面代码怎么写,内容包括JS获取页面某段HTML代码,求通过js获取html页面内容代码,怎么用JS获取某一个指定页面(非本页面)的HTML代码。用ajax。引入jquery的话,$("button").click(function(){$("div").load(test.htm

[/e:loop]