edtFTPj,FileTransferClient

edtFTPj的FileTransferClient类

 1 public class EdtFtpFreeTest {
 2 
 3     public static void main(String[] args) {
 4         String ftp_url = "127.0.0.1";
 5         String ftp_username = "username";
 6         String ftp_password = "password";
 7         String ftp_path = "remote path";
 8         // 本地文件路径
 9         String file_path = "local path name";
10         //上传服务器上文件名
11         String remoteFile = "remote file name";
12 
13         FileTransferClient ftp = new FileTransferClient();
14         try {
15             ftp.setRemoteHost(ftp_url);
16             ftp.setUserName(ftp_username);
17             ftp.setPassword(ftp_password);
18             ftp.connect();
19             ftp.setContentType(FTPTransferType.BINARY);
20             
21             ftp.changeDirectory(ftp_path);
22             //直接上传
23             ftp.uploadFile(file_path, remoteFile, WriteMode.RESUME);
24             
25             //构造文件流上传
26             OutputStream os = ftp.uploadStream(remoteFile);
27             FileInputStream is = new FileInputStream(file_path);
28             byte[] bytes = new byte[1024];
29             int c;
30             while ((c = is.read(bytes)) != -1) {
31                 os.write(bytes, 0, c);
32             }
33             is.close();
34             os.close();
35             is = null;
36             os = null;
37             
38             ftp.disconnect();
39         } catch (FTPException e) {
40             e.printStackTrace();
41         } catch (IOException e) {
42             e.printStackTrace();
43         }
44     }
45 }
View Code

 

转载于:https://www.cnblogs.com/Harriet/p/4864823.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值