(二)、edtFTPj FileTransferClient

系统 1725 0

edtFTPj的FileTransferClient类简单易用,而且下载的组件包中文档丰富,参考使用,完全能满足自己需要。

下载地址为: http://www.enterprisedt.com/index.html

废话不多说,上代码:

Java代码
  1. public class EdtFtpFreeTest{
  2. public static void main(String[]args){
  3. Stringftp_url= "127.0.0.1" ;
  4. Stringftp_username= "username" ;
  5. Stringftp_password= "password" ;
  6. Stringftp_path= "remotepath" ;
  7. //本地文件路径
  8. Stringfile_path= "localpathname" ;
  9. //上传服务器上文件名
  10. StringremoteFile= "remotefilename" ;
  11. FileTransferClientftp= new FileTransferClient();
  12. try {
  13. ftp.setRemoteHost(ftp_url);
  14. ftp.setUserName(ftp_username);
  15. ftp.setPassword(ftp_password);
  16. ftp.connect();
  17. ftp.setContentType(FTPTransferType.BINARY);
  18. ftp.changeDirectory(ftp_path);
  19. //直接上传
  20. ftp.uploadFile(file_path,remoteFile,WriteMode.RESUME);
  21. //构造文件流上传
  22. OutputStreamos=ftp.uploadStream(remoteFile);
  23. FileInputStreamis= new FileInputStream(file_path);
  24. byte []bytes= new byte [ 1024 ];
  25. int c;
  26. while ((c=is.read(bytes))!=- 1 ){
  27. os.write(bytes, 0 ,c);
  28. }
  29. is.close();
  30. os.close();
  31. is= null ;
  32. os= null ;
  33. ftp.disconnect();
  34. } catch (FTPExceptione){
  35. e.printStackTrace();
  36. } catch (IOExceptione){
  37. e.printStackTrace();
  38. }
  39. }
  40. }

(二)、edtFTPj FileTransferClient


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论