ftp创建文件夹|java 实现ftp上传如何创建文件夹

ftp创建文件夹|java 实现ftp上传如何创建文件夹的第1张示图

⑴ 在客户端中,如何在ftp服务器上创建文件夹

打开ftp://*.*.*.*,用有写入权限的帐户登陆,右键就有创建文件夹,

⑵ java 实现ftp上传如何创建文件夹

这个功能我也刚写完,不过我也是得益于同行,现在我也把自己的分享给大家,希望能对大家有所帮助,因为自己的项目不涉及到创建文件夹,也仅作分享,不喜勿喷谢谢!

interface:packagecom.sunline.bank.ftputil;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;importorg.apache.commons.net.ftp.FTPClient;publicinterfaceIFtpUtils{/***ftp登录*@paramhostname主机名*@paramport端口号*@paramusername用户名*@parampassword密码*@return*/publicFTPClientloginFtp(Stringhostname,Integerport,Stringusername,Stringpassword);/***上穿文件*@paramhostname主机名*@paramport端口号*@paramusername用户名*@parampassword密码*@paramfpathftp路径*@paramlocalpath本地路径*@paramfileName文件名*@return*/(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName);/***批量下载文件*@paramhostname*@paramport*@paramusername*@parampassword*@paramfpath*@paramlocalpath*@paramfileName源文件名*@paramfilenames需要修改成的文件名*@return*/publicbooleandownloadFileList(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName,Stringfilenames);/***修改文件名*@paramlocalpath*@paramfileName源文件名*@paramfilenames需要修改的文件名*/(Stringlocalpath,StringfileName,Stringfilenames);/***关闭流连接、ftp连接*@paramftpClient*@parambufferRead*@parambuffer*/publicvoidcloseFtpConnection(FTPClientftpClient,,BufferedInputStreambuffer);}impl:packagecom.sunline.bank.ftputil;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;importorg.apache.commons.net.ftp.FTPClient;importorg.apache.commons.net.ftp.FTPFile;importorg.apache.commons.net.ftp.FTPReply;importcommon.Logger;{privatestaticLoggerlog=Logger.getLogger(FtpUtilsImpl.class);FTPClientftpClient=null;Integerreply=null;@OverridepublicFTPClientloginFtp(Stringhostname,Integerport,Stringusername,Stringpassword){ftpClient=newFTPClient();try{ftpClient.connect(hostname,port);ftpClient.login(username,password);ftpClient.setControlEncoding("utf-8");reply=ftpClient.getReplyCode();ftpClient.setDataTimeout(60000);ftpClient.setConnectTimeout(60000);//设置文件类型为二进制(避免解压缩文件失败)ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);//开通数据端口传输数据,避免阻塞ftpClient.enterLocalActiveMode();if(!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())){log.error("连接FTP失败,用户名或密码错误");}else{log.info("FTP连接成功");}}catch(Exceptione){if(!FTPReply.isPositiveCompletion(reply)){try{ftpClient.disconnect();}catch(IOExceptione1){log.error("登录FTP失败,请检查FTP相关配置信息是否正确",e1);}}}returnftpClient;}@Override@SuppressWarnings("resource")(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName){booleanflag=false;ftpClient=loginFtp(hostname,port,username,password);BufferedInputStreambuffer=null;try{buffer=newBufferedInputStream(newFileInputStream(localpath+fileName));ftpClient.changeWorkingDirectory(fpath);fileName=newString(fileName.getBytes("utf-8"),ftpClient.DEFAULT_CONTROL_ENCODING);if(!ftpClient.storeFile(fileName,buffer)){log.error("上传失败");returnflag;}buffer.close();ftpClient.logout();flag=true;returnflag;}catch(Exceptione){e.printStackTrace();}finally{closeFtpConnection(ftpClient,null,buffer);log.info("文件上传成功");}returnfalse;}@OverridepublicbooleandownloadFileList(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName,Stringfilenames){ftpClient=loginFtp(hostname,port,username,password);booleanflag=false;=null;if(fpath.startsWith("/")&&fpath.endsWith("/")){try{//切换到当前目录this.ftpClient.changeWorkingDirectory(fpath);this.ftpClient.enterLocalActiveMode();FTPFile[]ftpFiles=this.ftpClient.listFiles();for(FTPFilefiles:ftpFiles){if(files.isFile()){System.out.println("=================="+files.getName());FilelocalFile=newFile(localpath+"/"+files.getName());bufferRead=newBufferedOutputStream(newFileOutputStream(localFile));ftpClient.retrieveFile(files.getName(),bufferRead);bufferRead.flush();}}ftpClient.logout();flag=true;}catch(IOExceptione){e.printStackTrace();}finally{closeFtpConnection(ftpClient,bufferRead,null);log.info("文件下载成功");}}modifiedLocalFileName(localpath,fileName,filenames);returnflag;}@Override(Stringlocalpath,StringfileName,Stringfilenames){Filefile=newFile(localpath);File[]fileList=file.listFiles();if(file.exists()){if(null==fileList||fileList.length==0){log.error("文件夹是空的");}else{for(Filedata:fileList){Stringorprefix=data.getName().substring(0,data.getName().lastIndexOf("."));Stringprefix=fileName.substring(0,fileName.lastIndexOf("."));System.out.println("index==="+orprefix+"prefix==="+prefix);if(orprefix.contains(prefix)){booleanf=data.renameTo(newFile(localpath+"/"+filenames));System.out.println("f============="+f);}else{log.error("需要重命名的文件不存在,请检查。。。");}}}}}@OverridepublicvoidcloseFtpConnection(FTPClientftpClient,,BufferedInputStreambuffer){if(ftpClient.isConnected()){try{ftpClient.disconnect();}catch(IOExceptione){e.printStackTrace();}}if(null!=bufferRead){try{bufferRead.close();}catch(IOExceptione){e.printStackTrace();}}if(null!=buffer){try{buffer.close();}catch(IOExceptione){e.printStackTrace();}}}publicstaticvoidmain(String[]args)throwsIOException{Stringhostname="xx.xxx.x.xxx";Integerport=21;Stringusername="edwftp";Stringpassword="edwftp";Stringfpath="/etl/etldata/back/";StringlocalPath="C:/Users/Administrator/Desktop/ftp下载/";StringfileName="test.txt";Stringfilenames="ok.txt";FtpUtilsImplftp=newFtpUtilsImpl();/*ftp.modifiedLocalFileName(localPath,fileName,filenames);*/ftp.downloadFileList(hostname,port,username,password,fpath,localPath,fileName,filenames);/*ftp.uploadLocalFilesToFtp(hostname,port,username,password,fpath,localPath,fileName);*//*ftp.modifiedLocalFileName(localPath);*/}}

⑶ ftp共享文档怎样实现新建功能

1、在电脑的任意一盘创建一个共享文件夹把它命名为ftp文件共享。2、把需要共享的文件放里面。3、安装IS组件,将Internet服务下面的选项全部勾选。4、之后重启电脑即可。

⑷ 如何在ftp上建立自己的文件夹

如果你有权限操作ftp的话,那么就像操作windows一样简单。右键-新建文件夹。不然就得求救网络管理员了

⑸ 怎么用bat封装 ftp://[email protected] 打开bat就能实现在我的电脑中创建一个文件夹

都不要批处理,只要用映射功能就行了,在映射的地方填入你的网络文件地址,简单方便,具体操作,打开计算机-空白处右键-选择添加一个网络位置,在里面输入你要添加网络文件夹的地址

⑹ win7 ftp怎么建立文件夹

在系统中任复何的文件夹都可以借制助于ftp服务成为共享文件夹,建立文件夹只需要在磁盘位置右键选择”新建文件夹“即可,ftp共享的设置方法可以参考如下操作:1、在win7上使用ftp服务,需要先安装iis服务,打开 "控制面板",选择"程序" -> "打开或关闭Windows资源",在弹出的窗体里找到 “Internet信息服务”,展开后选择“Ftp服务器",然后点击"确定",此时Windows开始更新功能资源列表。2、然后,自己在IIS管理器中添加FTP站点在弹出的窗口,选择ftp共享目录即可。

⑺ 怎么在FTP建立文件夹

1、创建要自己先链接要上传的远程,一般为远程地址,账户和密码,2、只要输入正确就行,这样是自己的本地和远程就连接上了,这样也可以进行本地和远程的文件传输了,3、然后再直接选择文件夹右键点击上传就行了。

⑻ win7系统下怎么建立个ftp共享文件夹

在系统中任何的文件夹都可以借助于ftp服务成为共享文件夹,建立文件夹只需要在磁盘位置右键选择”新建文件夹“即可,ftp共享的设置方法可以参考如下操作:1、在win7上使用ftp服务,需要先安装iis服务,打开"控制面板",选择"程序"->"打开或关闭Windows资源",在弹出的窗体里找到“Internet信息服务”,展开后选择“Ftp服务器",然后点击"确定",此时Windows开始更新功能资源列表。2、然后,自己在IIS管理器中添加FTP站点在弹出的窗口,选择ftp共享目录即可。

⑼ 如何在FTP里新建文件夹

确定权限没有问题?那你试试拉个本地文件夹上去,复制进去个文件夹跟新建个文件夹原理是一样的

⑽ ftp不能新建文件夹

ftp不能新建文件夹是设置错误造成的,解决方法为:

1、打开后,找到左上角的【站点】并用版鼠标左键点击。

未经允许不得转载:山九号 » ftp创建文件夹|java 实现ftp上传如何创建文件夹

赞 (0)