北晨同志 發表於 2019-12-22 21:52:00

linux搭建ftp服务器

<p><span style="font-size: 15px">FTP,即:文件传输协议(File Transfer Protocol),基于客户端/服务器模式,默认使用20、21端口号,其</span><br><span style="font-size: 15px">中端口20(数据端口)用于进行数据传输,端口21(命令端口)用于接受客户端发出的相关FTP命令与参</span><br><span style="font-size: 15px">数。FTP服务器普遍部署于局域网中,具有容易搭建、方便管理的特点。而且有些FTP客户端工具还可以支</span><br><span style="font-size: 15px">持文件的多点下载以及断点续传技术,因此FTP服务得到了广大用户的青睐。</span></p>
<p><br><strong>FTP协议有以下两种工作模式:</strong><br><span style="font-size: 15px">主动模式(PORT):FTP服务器主动向客户端发起连接请求。</span><br><span style="font-size: 15px">被动模式(PASV):FTP服务器等待客户端发起连接请求(FTP的默认工作模式)。</span><br><span style="font-size: 15px">vsftpd是一款运行在Linux操作系统上的FTP服务程序,具有很高的安全性和传输速度。</span></p>
<p><br><strong>vsftpd有以下三种认证模式:</strong><br><span style="font-size: 15px">匿名开放模式:是一种最不安全的认证模式,任何人都可以无需密码验证而直接登陆。</span><br><span style="font-size: 15px">本地用户模式:是通过Linux系统本地的账户密码信息进行认证的模式,相较于匿名开放模式更安全,而且</span><br><span style="font-size: 15px">配置起来简单。</span><br><span style="font-size: 15px">虚拟用户模式:是这三种模式中最安全的一种认证模式,它需要为FTP服务单独建立用户数据库文件,虚</span><br><span style="font-size: 15px">拟出用来进行口令验证的账户信息,而这些账户信息在服务器系统中实际上是不存在的,仅供FTP服务程</span><br><span style="font-size: 15px">序进行认证使用。</span></p>
<p>&nbsp;</p>
<p><strong>下面以虚拟用户模式配置讲解</strong></p>
<p><strong><span style="color: rgba(0, 0, 255, 1)"><span style="font-size: 18px">1</span><span style="font-size: 15px">.输入图中命令,若输出图中信息表示已安装vsftpd,否则输入命令:<strong>yum install -y vsftpd 进行安装</strong></span></span></strong></p>
<p><strong><span style="color: rgba(0, 0, 255, 1)"><img src="https://img2018.cnblogs.com/common/1738754/201912/1738754-20191222193207277-513953278.png"></span></strong></p>
<p>&nbsp;</p>
<p><strong><span style="font-size: 18px; color: rgba(0, 0, 255, 1)">2<span style="font-size: 15px">.</span></span><span style="color: rgba(0, 0, 255, 1); font-size: 15px">安装完成后</span></strong></p>
<p><span style="color: rgba(0, 0, 255, 1); font-size: 15px"><span style="color: rgba(0, 0, 0, 1)">vsftpd缺省安装在<strong>/etc/vsftpd/</strong>目录中,进入该目录后如下所示</span></span><strong><span style="color: rgba(0, 0, 255, 1); font-size: 15px"><br></span></strong></p>
<p><span style="color: rgba(0, 0, 255, 1); font-size: 15px"><span style="color: rgba(0, 0, 0, 1)"><img src="https://img2018.cnblogs.com/common/1738754/201912/1738754-20191222194058119-1276740593.png"></span></span></p>
<p>&nbsp;</p>
<p><strong>1.vsftpd.conf:为核心配置文件</strong></p>
<p><strong>2.user_list:指定允许使用vsftpd 的用户列表文件,即<strong>白名单</strong></strong></p>
<p><strong><strong>3.ftpusers:指定哪些用户不能访问FTP服务器,即<strong>黑名单</strong></strong></strong></p>
<p><strong>4.如需去掉配置文件里的注释行输入以下命令即可</strong></p>
<p><span style="font-size: 15px">mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak</span><br><span style="font-size: 15px">grep -v "#" /etc/vsftpd/vsftpd.conf.bak &gt; /etc/vsftpd/vsftpd.conf</span></p>
<p><strong>5.vsftpd.conf常用配置参数讲解</strong></p>
<p><strong>listen=&lt;YES/NO&gt;&nbsp; # YES: 服务以独立运行方式运行; NO: 运行在 xinetd 内。 默认为 YES<br></strong></p>
<p><strong>listen_address=&lt;ip address&gt; # 服务监听地址, 如果有多个网卡, 需要将服务绑定到指定 IP 地址</strong></p>
<p><strong>listen_port=&lt;port&gt; # 服务监听端口, 默认为 21</strong></p>
<p><strong>anonymous_enable=&lt;YES/NO&gt; # 是否允许匿名用户访问, 默认 NO</strong></p>
<p><strong>anon_mkdir_write_enable=&lt;YES/NO&gt; # 是否允许匿名用户创建文件夹, 默认 NO</strong></p>
<p><strong>anon_other_write_enable=&lt;YES/NO&gt; # 是否允许匿名用户其他的写权限, 创建文件、重命名、删除文件等权限 默认为 NO</strong></p>
<p><strong>anon_upload_enable=&lt;YES/NO&gt; # 是否允许匿名用户上传, 默认 NO</strong></p>
<p><strong>anon_umask=&lt;nnn&gt; # 匿名用户上传的文件的生成掩码, 默认为077</strong></p>
<p><strong>anon_max_rate=&lt;n&gt; # 匿名用户的最大传输速率, 单位为 Byte/s, 值为 0 表示不限制</strong></p>
<p><strong>anon_world_readable_only=&lt;YES/NO&gt; # 是否允许匿名用户只读浏览</strong></p>
<p><strong>local_enable=&lt;YES/NO&gt; # 是否支持本地用户帐号访问</strong></p>
<p><strong>write_enable=&lt;YES/NO&gt; # 是否开放本地用户的写权限</strong></p>
<p><strong>local_umask=&lt;nnn&gt; # 本地用户上传的文件的生成掩码, 默认为077</strong></p>
<p><strong>local_max_rate=&lt;n&gt; # 本地用户最大的传输速率, 单位为 Byte/s,值为0表示不限制</strong></p>
<p><strong>local_root=&lt;file&gt; # 本地用户登陆后的目录,默认为本地用户的主目录</strong></p>
<p><strong>chroot_local_user=&lt;YES/NO&gt; # 本地用户是否可以执行 chroot, 默认为 NO</strong></p>
<p><strong>chroot_list_enable=&lt;YES/NO&gt; # 是否只有指定的用户才能执行 chroot, 默认为 NO</strong></p>
<p><strong>chroot_list_file=&lt;filename&gt; # 当 chroot_local_user=NO 且 chroot_list_enable=YES 时,</strong></p>
<p><strong>          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# 只有 filename 文件内指定的用户(每行一个用户名)可以执行 chroot,</strong></p>
<p><strong>            &nbsp; &nbsp;&nbsp;# 默认值为 /etc/vsftpd.chroot_list</strong></p>
<p><strong>userlist_enable=&lt;YES/NO&gt; # 是否启用 userlist_file 白/黑名单用户列表, 默认为 NO</strong></p>
<p><strong>userlist_deny=&lt;YES/NO&gt; # 当 userlist_enable=YES(即启用 userlist_file )时, 则该字段才有效。</strong></p>
<p><strong>userlist_deny=YES: userlist_file 为 黑名单, 即在该文件内的用户均不可登录, 其他用户可以登录</strong></p>
<p><strong>userlist_deny=NO: userlist_file 为 白名单, 即在该文件内的用户才可以登录, 其他用户均不可登录</strong></p>
<p><strong>userlist_file=&lt;filename&gt; # 黑/白名单用户列表文件(每行一个用户名)</strong></p>
<p><strong>           &nbsp; # 是黑名单还是白名单, 根据 userlist_deny 的值决定</strong></p>
<p><strong>          &nbsp; &nbsp; &nbsp;# 默认值为 /etc/vsftpd.user_list</strong></p>
<p><strong>ftpd_banner=&lt;message&gt; # 客户端连接服务器后显示的欢迎信息</strong></p>
<p><strong>connect_timeout=&lt;n&gt; # 远程客户端响应端口数据连接超时时间, 单位为秒, 默认 60</strong></p>
<p><strong>accept_connection_timeout=&lt;n&gt; # 空闲的数据连接超时时间, 单位为秒, 默认 120</strong></p>
<p><strong>data_connection_timeout=&lt;n&gt; # 空闲的用户会话超时时间, 单位为秒, 默认 300</strong></p>
<p><strong>max_clients=&lt;n&gt; # 在独立模式运行时, 最大连接数, 0 表示无限制</strong></p>
<p><strong>max_per_ip=&lt;n&gt; # 在独立模式运行时, 每 IP 的最大连接数, 0表示无限制</strong></p>
<p><strong>pasv_min_port=45000 # PASV模式最小端口</strong></p>
<p><strong>pasv_max_port=49999&nbsp;&nbsp;# PASV模式最大端口</strong></p>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 255, 1); font-size: 15px"><strong><strong><span style="font-size: 18px">3</span>.配置防火墙开放vsftpd命令端口与PASV模式下的端口</strong></strong></span></p>
<p><span style="color: rgba(0, 0, 0, 1)"><strong><strong>firewall-cmd --zone=<span class="hljs-keyword">public --add-port=<span class="hljs-number">21/tcp --permanent</span></span></strong></strong></span></p>
<p><span><strong><strong>firewall-cmd --zone=<span class="hljs-keyword">public --add-port=45000-49000<span class="hljs-number">/tcp --permanent</span></span></strong></strong></span></p>
<p><strong>firewall-cmd --reload</strong></p>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 255, 1); font-size: 15px"><strong><strong><strong><span style="font-size: 18px">4</span>.创建用于FTP认证的用户数据库文件</strong></strong></strong></span></p>
<p>vim /etc/vsftpd/vuser.txt</p>
<p>其中奇数行为用户名,偶数行为密码</p>
<p>如:</p>
<p>xuyuanyuan</p>
<p>123456</p>
<p>chendanting</p>
<p>123456</p>
<p>明文信息不安全,需要使用db_load命令用哈希(hash)算法将明文信息转换成数据文件,然后将明文信息文件删除</p>
<p><strong>db_load -T -t hash -f /etc/vsftpd/vuser.txt /etc/vsftpd/vuser.db</strong><br><strong>chmod 600 /etc/vsftpd/vuser.db</strong><br><strong>rm -f /etc/vsftpd/vuser.txt</strong></p>
<p>&nbsp;</p>
<p><strong><span style="font-size: 15px; color: rgba(0, 0, 255, 1)"><span style="font-size: 18px">5.</span>创建虚拟用户映射的系统本地用户和FTP根目录</span></strong></p>
<p>输入命令:</p>
<p><strong>useradd -d /ftp_data -s /sbin/nologin virtual</strong></p>
<p><strong>chmod -Rf 755 /ftp_data</strong></p>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 255, 1)"><strong><strong><span style="font-size: 18px">6</span><span style="font-size: 15px">.建立用于支持虚拟用户的PAM文件</span></strong></strong></span></p>
<p>PAM(可插拔认证模块)是一种认证机制,通过一些动态链接库和统一的API把系统提供的服务与认证方式分<br>开,使得系统管理员可以根据需求灵活调整服务程序的不同认证方式。PAM采用了分层设计(应用程序层、<br>应用接口层、鉴别模块层)的思想,其结构如下图所示。</p>
<p><img src="https://img2018.cnblogs.com/common/1738754/201912/1738754-20191222210301693-529527519.png"></p>
<p><strong>vim /etc/pam.d/vsftpd.vu</strong></p>
<p><strong>添加以下信息</strong><br><strong>auth&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;required&nbsp; &nbsp; pam_userdb.so&nbsp; &nbsp; db=/etc/vsftpd/vuser</strong><br><strong>account&nbsp; &nbsp;required&nbsp; &nbsp; pam_userdb.so&nbsp; &nbsp; db=/etc/vsftpd/vuser</strong></p>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 255, 1)"><strong><strong><span style="font-size: 18px">6</span>.<span style="font-size: 15px">为vuser.txt里的用户配置相关参数</span></strong></strong></span></p>
<p><strong><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">(1) 创建存放用户的目录</span></span></strong></p>
<p><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">mkdir /etc/vsftpd/vusers_dir</span></span></p>
<p><strong><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">(2) 为各用户创建文件,文件名即为用户名</span></span></strong></p>
<p><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">vim /etc/vsftpd/vusers_dir/xuyuanyuan</span></span></p>
<p><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">vim /etc/vsftpd/vusers_dir/chendanting</span></span></p>
<p>&nbsp;</p>
<p><strong><span style="font-size: 15px">(3) 按各用户需要加入参数配置</span></strong></p>
<p><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">local_root=/ftp_data/xuyuanyuan</span></span></p>
<p>anon_upload_enable=YES</p>
<p>anon_mkdir_write_enable=YES</p>
<p>anon_other_write_enable=YES</p>
<p>anon_world_readable_only=YES</p>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 255, 1)"><strong><strong><span style="font-size: 18px">6</span>.<span style="font-size: 15px">修改核心配置文件vsftpd.conf为以下内容</span></strong></strong></span></p>
<p>anonymous_enable=NO</p>
<p>local_enable=YES</p>
<p># 开启虚拟用户模式<br>guest_enable=YES</p>
<p># 指定虚拟用户对应的系统用户<br>guest_username=virtual</p>
<p># 允许对ftp根目录执行写入操作<br>allow_writeable_chroot=YES</p>
<p>write_enable=YES</p>
<p>local_umask=022</p>
<p>dirmessage_enable=YES</p>
<p>xferlog_enable=YES</p>
<p>connect_from_port_20=YES</p>
<p>xferlog_std_format=YES</p>
<p>listen_port=21</p>
<p>listen=NO</p>
<p>listen_ipv6=YES</p>
<p>#PAM文件</p>
<p>pam_service_name=vsftpd.vu</p>
<p>userlist_enable=YES</p>
<p>tcp_wrappers=YES</p>
<p># 虚拟用户配置文件目录<br>user_config_dir=/etc/vsftpd/vuser_dir</p>
<p># 被动模式端口范围<br>pasv_min_port=45000</p>
<p>pasv_max_port=49000</p>
<p>chroot_local_user=YES</p>
<p>&nbsp;</p>
<p><span style="font-size: 15px"><strong><span style="color: rgba(0, 0, 255, 1)"><span style="font-size: 18px">7</span>.最后启动服务即可访问</span></strong></span></p>
<p><span style="font-size: 15px; color: rgba(0, 0, 0, 1)">systemctl start vsftpd.serivce 启动服务</span></p>
<p><span style="font-size: 15px; color: rgba(0, 0, 0, 1)">systemctl stop vsftpd.serivce 停止服务</span></p>
<p><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">systemctl status vsftpd.serivce 查看服务状态</span></span></p>
<p><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">systemctl restart vsftpd.serivce 查看服务状态</span></span></p>
<p><span style="color: rgba(0, 0, 0, 1)"><span style="font-size: 15px">在浏览器输入&nbsp;ftp://ip:21 就可访问了</span></span></p>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 0, 1); font-size: 18px"><strong><strong>最后配上操作ftp的工具类</strong></strong></span></p>
<p><span style="color: rgba(0, 0, 0, 1)">maven依赖</span></p>
<p>&lt;dependency&gt;<br>              &lt;groupId&gt;commons-net&lt;/groupId&gt;<br>              &lt;artifactId&gt;commons-net&lt;/artifactId&gt;<br>              &lt;version&gt;3.6&lt;/version&gt;<br>      &lt;/dependency&gt;</p>
<div class="cnblogs_code"><img id="code_img_closed_4129dc2f-423c-4ae7-9c13-b40febdc20c2" class="code_img_closed lazyload" alt="" data-src="http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif"><img id="code_img_opened_4129dc2f-423c-4ae7-9c13-b40febdc20c2" class="code_img_opened lazyload" style="display: none" alt="" data-src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif">
<div id="cnblogs_code_open_4129dc2f-423c-4ae7-9c13-b40febdc20c2" class="cnblogs_code_hide">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">2</span> <span style="color: rgba(0, 128, 0, 1)"> * </span><span style="color: rgba(128, 128, 128, 1)">@author</span><span style="color: rgba(0, 128, 0, 1)"> Medusa
</span><span style="color: rgba(0, 128, 128, 1)">3</span> <span style="color: rgba(0, 128, 0, 1)"> * @Date 12-14-19
</span><span style="color: rgba(0, 128, 128, 1)">4</span> <span style="color: rgba(0, 128, 0, 1)"> * @Description ftp工具类
</span><span style="color: rgba(0, 128, 128, 1)">5</span><span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">6</span> <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> FtpUtil {
</span><span style="color: rgba(0, 128, 128, 1)">7</span>
<span style="color: rgba(0, 128, 128, 1)">8</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">9</span> <span style="color: rgba(0, 128, 0, 1)">   * ftp服务器的ip
</span><span style="color: rgba(0, 128, 128, 1)"> 10</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 11</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String ip;
</span><span style="color: rgba(0, 128, 128, 1)"> 12</span>
<span style="color: rgba(0, 128, 128, 1)"> 13</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)"> 14</span> <span style="color: rgba(0, 128, 0, 1)">   * ftp服务器的端口,缺省为21
</span><span style="color: rgba(0, 128, 128, 1)"> 15</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 16</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> port;
</span><span style="color: rgba(0, 128, 128, 1)"> 17</span>
<span style="color: rgba(0, 128, 128, 1)"> 18</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)"> 19</span> <span style="color: rgba(0, 128, 0, 1)">   * 连接ftp服务器的用户名
</span><span style="color: rgba(0, 128, 128, 1)"> 20</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 21</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String userName;
</span><span style="color: rgba(0, 128, 128, 1)"> 22</span>
<span style="color: rgba(0, 128, 128, 1)"> 23</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)"> 24</span> <span style="color: rgba(0, 128, 0, 1)">   * 用户名对应通行证
</span><span style="color: rgba(0, 128, 128, 1)"> 25</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 26</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String password;
</span><span style="color: rgba(0, 128, 128, 1)"> 27</span>
<span style="color: rgba(0, 128, 128, 1)"> 28</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)"> 29</span> <span style="color: rgba(0, 128, 0, 1)">   * 客户端编码
</span><span style="color: rgba(0, 128, 128, 1)"> 30</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 31</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> String clientCharset = "GBK"<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 32</span>
<span style="color: rgba(0, 128, 128, 1)"> 33</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)"> 34</span> <span style="color: rgba(0, 128, 0, 1)">   * 服务端编码,缺省为ISO8859-1
</span><span style="color: rgba(0, 128, 128, 1)"> 35</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 36</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> String serverCharset = "ISO8859-1"<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 37</span>
<span style="color: rgba(0, 128, 128, 1)"> 38</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> FTPClient ftpClient;
</span><span style="color: rgba(0, 128, 128, 1)"> 39</span>
<span style="color: rgba(0, 128, 128, 1)"> 40</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> FtpUtil(String ip, <span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> port, String userName, String password) {
</span><span style="color: rgba(0, 128, 128, 1)"> 41</span>         <span style="color: rgba(0, 0, 255, 1)">this</span>.ip =<span style="color: rgba(0, 0, 0, 1)"> ip;
</span><span style="color: rgba(0, 128, 128, 1)"> 42</span>         <span style="color: rgba(0, 0, 255, 1)">this</span>.port =<span style="color: rgba(0, 0, 0, 1)"> port;
</span><span style="color: rgba(0, 128, 128, 1)"> 43</span>         <span style="color: rgba(0, 0, 255, 1)">this</span>.userName =<span style="color: rgba(0, 0, 0, 1)"> userName;
</span><span style="color: rgba(0, 128, 128, 1)"> 44</span>         <span style="color: rgba(0, 0, 255, 1)">this</span>.password =<span style="color: rgba(0, 0, 0, 1)"> password;
</span><span style="color: rgba(0, 128, 128, 1)"> 45</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)"> 46</span>
<span style="color: rgba(0, 128, 128, 1)"> 47</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)"> 48</span> <span style="color: rgba(0, 128, 0, 1)">   * 建立连接并登陆服务器
</span><span style="color: rgba(0, 128, 128, 1)"> 49</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 50</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> connectFtp() {
</span><span style="color: rgba(0, 128, 128, 1)"> 51</span>         ftpClient = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> FTPClient();
</span><span style="color: rgba(0, 128, 128, 1)"> 52</span>
<span style="color: rgba(0, 128, 128, 1)"> 53</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)"> 54</span> <span style="color: rgba(0, 0, 0, 1)">            ftpClient.connect(ip, port);
</span><span style="color: rgba(0, 128, 128, 1)"> 55</span>
<span style="color: rgba(0, 128, 128, 1)"> 56</span>             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 是否连接成功</span>
<span style="color: rgba(0, 128, 128, 1)"> 57</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
</span><span style="color: rgba(0, 128, 128, 1)"> 58</span>               System.out.println("create connect fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)"> 59</span> <span style="color: rgba(0, 0, 0, 1)">                ftpClient.disconnect();
</span><span style="color: rgba(0, 128, 128, 1)"> 60</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 61</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 62</span>
<span style="color: rgba(0, 128, 128, 1)"> 63</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">ftpClient.login(userName, password)) {
</span><span style="color: rgba(0, 128, 128, 1)"> 64</span>               System.out.println("login server fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)"> 65</span> <span style="color: rgba(0, 0, 0, 1)">                ftpClient.disconnect();
</span><span style="color: rgba(0, 128, 128, 1)"> 66</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 67</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 68</span>
<span style="color: rgba(0, 128, 128, 1)"> 69</span>             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则使用本地编码</span>
<span style="color: rgba(0, 128, 128, 1)"> 70</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"<span style="color: rgba(0, 0, 0, 1)">))) {
</span><span style="color: rgba(0, 128, 128, 1)"> 71</span>               clientCharset = "UTF-8"<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 72</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 73</span> <span style="color: rgba(0, 0, 0, 1)">            ftpClient.setControlEncoding(clientCharset);
</span><span style="color: rgba(0, 128, 128, 1)"> 74</span>             ftpClient.enterLocalPassiveMode(); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 设置被动模式</span>
<span style="color: rgba(0, 128, 128, 1)"> 75</span>             ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 设置文件传输类型</span>
<span style="color: rgba(0, 128, 128, 1)"> 76</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)"> 77</span>             System.out.println("create connect or close connect error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)"> 78</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 79</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)"> 80</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 81</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)"> 82</span>
<span style="color: rgba(0, 128, 128, 1)"> 83</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)"> 84</span> <span style="color: rgba(0, 128, 0, 1)">   * 退出登陆并关闭连接
</span><span style="color: rgba(0, 128, 128, 1)"> 85</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)"> 86</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> closeFtp() {
</span><span style="color: rgba(0, 128, 128, 1)"> 87</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpClient != <span style="color: rgba(0, 0, 255, 1)">null</span> &amp;&amp;<span style="color: rgba(0, 0, 0, 1)"> ftpClient.isConnected()) {
</span><span style="color: rgba(0, 128, 128, 1)"> 88</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)"> 89</span> <span style="color: rgba(0, 0, 0, 1)">                ftpClient.logout();
</span><span style="color: rgba(0, 128, 128, 1)"> 90</span> <span style="color: rgba(0, 0, 0, 1)">                ftpClient.disconnect();
</span><span style="color: rgba(0, 128, 128, 1)"> 91</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 92</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)"> 93</span>               System.out.println("logout or close connect error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)"> 94</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 95</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 96</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)"> 97</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)"> 98</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)"> 99</span>
<span style="color: rgba(0, 128, 128, 1)">100</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">101</span> <span style="color: rgba(0, 128, 0, 1)">   * 客户端转服务端编码
</span><span style="color: rgba(0, 128, 128, 1)">102</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">103</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String clientCharsetToServer(String path) {
</span><span style="color: rgba(0, 128, 128, 1)">104</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">105</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> String(path.getBytes(clientCharset), serverCharset);
</span><span style="color: rgba(0, 128, 128, 1)">106</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (UnsupportedEncodingException e) {
</span><span style="color: rgba(0, 128, 128, 1)">107</span>             System.out.println("client to server encode error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">108</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">109</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">110</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">111</span>
<span style="color: rgba(0, 128, 128, 1)">112</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">113</span> <span style="color: rgba(0, 128, 0, 1)">   * 服务端转客户端编码
</span><span style="color: rgba(0, 128, 128, 1)">114</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">115</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String serverCharsetToClient(String path) {
</span><span style="color: rgba(0, 128, 128, 1)">116</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">117</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> String(path.getBytes(serverCharset), clientCharset);
</span><span style="color: rgba(0, 128, 128, 1)">118</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (UnsupportedEncodingException e) {
</span><span style="color: rgba(0, 128, 128, 1)">119</span>             System.out.println("server to client encode error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">120</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">121</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">122</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">123</span>
<span style="color: rgba(0, 128, 128, 1)">124</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">125</span> <span style="color: rgba(0, 128, 0, 1)">   * 获取当前工作目录
</span><span style="color: rgba(0, 128, 128, 1)">126</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">127</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String getWorkDirectory() {
</span><span style="color: rgba(0, 128, 128, 1)">128</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">129</span>             <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> serverCharsetToClient(ftpClient.printWorkingDirectory());
</span><span style="color: rgba(0, 128, 128, 1)">130</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">131</span>             System.out.println("get work directory error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">132</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">133</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">134</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">135</span>
<span style="color: rgba(0, 128, 128, 1)">136</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">137</span> <span style="color: rgba(0, 128, 0, 1)">   * 获取当前工作目录下的所有文件名
</span><span style="color: rgba(0, 128, 128, 1)">138</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">139</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> String[] getWorkDirectoryFileNames() {
</span><span style="color: rgba(0, 128, 128, 1)">140</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">141</span>             FTPFile[] ftpFiles =<span style="color: rgba(0, 0, 0, 1)"> ftpClient.listFiles();
</span><span style="color: rgba(0, 128, 128, 1)">142</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpFiles.length &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">143</span>               String[] fileNames = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> String;
</span><span style="color: rgba(0, 128, 128, 1)">144</span>               <span style="color: rgba(0, 0, 255, 1)">int</span> i = 0<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">145</span>
<span style="color: rgba(0, 128, 128, 1)">146</span>               <span style="color: rgba(0, 0, 255, 1)">for</span> (FTPFile ftpFile: ftpFiles) fileNames =<span style="color: rgba(0, 0, 0, 1)"> ftpFile.getName();
</span><span style="color: rgba(0, 128, 128, 1)">147</span>
<span style="color: rgba(0, 128, 128, 1)">148</span>               <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> fileNames;
</span><span style="color: rgba(0, 128, 128, 1)">149</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">150</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">151</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">152</span>             System.out.println("get work directory files error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">153</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">154</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">155</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">156</span>
<span style="color: rgba(0, 128, 128, 1)">157</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">158</span> <span style="color: rgba(0, 128, 0, 1)">   * 根据从根目录开始的完整文件路径,切换工作目录
</span><span style="color: rgba(0, 128, 128, 1)">159</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">160</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> changeWorkDirectory(String path) {
</span><span style="color: rgba(0, 128, 128, 1)">161</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">162</span>             <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> ftpClient.changeWorkingDirectory(clientCharsetToServer(path));
</span><span style="color: rgba(0, 128, 128, 1)">163</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">164</span>             System.out.println("change directory error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">165</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">166</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">167</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">168</span>
<span style="color: rgba(0, 128, 128, 1)">169</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">170</span> <span style="color: rgba(0, 128, 0, 1)">   * 当前工作目录下是否有查询的文件
</span><span style="color: rgba(0, 128, 128, 1)">171</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">172</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> isWorkDirectoryHasFile(String fileName) {
</span><span style="color: rgba(0, 128, 128, 1)">173</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">174</span>             FTPFile[] ftpFiles =<span style="color: rgba(0, 0, 0, 1)"> ftpClient.listFiles();
</span><span style="color: rgba(0, 128, 128, 1)">175</span>
<span style="color: rgba(0, 128, 128, 1)">176</span>             <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (FTPFile ftpFile : ftpFiles) {
</span><span style="color: rgba(0, 128, 128, 1)">177</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpFile.getName().equals(fileName)) <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">178</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">179</span>
<span style="color: rgba(0, 128, 128, 1)">180</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">181</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">182</span>             System.out.println("get work directory files error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">183</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">184</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">185</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">186</span>
<span style="color: rgba(0, 128, 128, 1)">187</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">188</span> <span style="color: rgba(0, 128, 0, 1)">   *获取对应路径下的文件(根目录除外),并切换工作目录至此文件的父目录
</span><span style="color: rgba(0, 128, 128, 1)">189</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">190</span>   <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> FTPFile getFTPFile(String path) {
</span><span style="color: rgba(0, 128, 128, 1)">191</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (path.equals("/"<span style="color: rgba(0, 0, 0, 1)">)) {
</span><span style="color: rgba(0, 128, 128, 1)">192</span>             System.out.println("invalid root directory"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">193</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">194</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">195</span>
<span style="color: rgba(0, 128, 128, 1)">196</span>         String fileName =<span style="color: rgba(0, 0, 0, 1)"> path;
</span><span style="color: rgba(0, 128, 128, 1)">197</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (!path.equals("/") &amp;&amp; path.indexOf("/") != -1<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">198</span>             String[] split = path.split("/"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">199</span>             fileName = split;
</span><span style="color: rgba(0, 128, 128, 1)">200</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">201</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (changeWorkDirectory(path.substring(0, path.length() -<span style="color: rgba(0, 0, 0, 1)"> fileName.length()))) {
</span><span style="color: rgba(0, 128, 128, 1)">202</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">203</span>               <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (FTPFile ftpFile : ftpClient.listFiles()) {
</span><span style="color: rgba(0, 128, 128, 1)">204</span>                     <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpFile.getName().equals(fileName)) <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> ftpFile;
</span><span style="color: rgba(0, 128, 128, 1)">205</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">206</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">207</span>               System.out.println("get work directory files error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">208</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">209</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">210</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">211</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">212</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">213</span>
<span style="color: rgba(0, 128, 128, 1)">214</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">215</span> <span style="color: rgba(0, 128, 0, 1)">   * 获取服务端文件夹下所有文件路径
</span><span style="color: rgba(0, 128, 128, 1)">216</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">217</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> List&lt;List&lt;String&gt;&gt; getDirectoryUnderAllFile(String path) <span style="color: rgba(0, 0, 255, 1)">throws</span><span style="color: rgba(0, 0, 0, 1)"> IOException {
</span><span style="color: rgba(0, 128, 128, 1)">218</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 存放目录和文件的路径</span>
<span style="color: rgba(0, 128, 128, 1)">219</span>         List&lt;List&lt;String&gt;&gt; directoryAndFilePaths = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">220</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 存放目录的路径</span>
<span style="color: rgba(0, 128, 128, 1)">221</span>         List&lt;String&gt; directoryPaths = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">222</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 存放文件的路径</span>
<span style="color: rgba(0, 128, 128, 1)">223</span>         List&lt;String&gt; filePaths = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">224</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 待遍历处理的文件夹路径</span>
<span style="color: rgba(0, 128, 128, 1)">225</span>         Queue&lt;String&gt; ergodicDirPaths = <span style="color: rgba(0, 0, 255, 1)">new</span> LinkedList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">226</span> <span style="color: rgba(0, 0, 0, 1)">      ergodicDirPaths.offer(path);
</span><span style="color: rgba(0, 128, 128, 1)">227</span> <span style="color: rgba(0, 0, 0, 1)">      directoryPaths.add(path);
</span><span style="color: rgba(0, 128, 128, 1)">228</span>         
<span style="color: rgba(0, 128, 128, 1)">229</span>         <span style="color: rgba(0, 0, 255, 1)">while</span> (ergodicDirPaths.size() &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">230</span>             String entry =<span style="color: rgba(0, 0, 0, 1)"> ergodicDirPaths.poll();
</span><span style="color: rgba(0, 128, 128, 1)">231</span>             <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (changeWorkDirectory(entry)) {
</span><span style="color: rgba(0, 128, 128, 1)">232</span>               entry = "/".endsWith(entry) ? ""<span style="color: rgba(0, 0, 0, 1)"> : entry;
</span><span style="color: rgba(0, 128, 128, 1)">233</span>               FTPFile[] ftpFiles =<span style="color: rgba(0, 0, 0, 1)"> ftpClient.listFiles();
</span><span style="color: rgba(0, 128, 128, 1)">234</span>               <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (FTPFile ftpFile : ftpFiles) {
</span><span style="color: rgba(0, 128, 128, 1)">235</span>                     <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (ftpFile.isFile()) {
</span><span style="color: rgba(0, 128, 128, 1)">236</span>                         filePaths.add(entry + "/" +<span style="color: rgba(0, 0, 0, 1)"> ftpFile.getName());
</span><span style="color: rgba(0, 128, 128, 1)">237</span>                     } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">238</span>                         directoryPaths.add(entry + "/" +<span style="color: rgba(0, 0, 0, 1)"> ftpFile.getName());
</span><span style="color: rgba(0, 128, 128, 1)">239</span>                         ergodicDirPaths.offer(entry + "/" +<span style="color: rgba(0, 0, 0, 1)"> ftpFile.getName());
</span><span style="color: rgba(0, 128, 128, 1)">240</span> <span style="color: rgba(0, 0, 0, 1)">                  }
</span><span style="color: rgba(0, 128, 128, 1)">241</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">242</span>             } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">243</span>               System.out.println("切换目录失败"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">244</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">245</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">246</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">247</span>
<span style="color: rgba(0, 128, 128, 1)">248</span> <span style="color: rgba(0, 0, 0, 1)">      directoryAndFilePaths.add(directoryPaths);
</span><span style="color: rgba(0, 128, 128, 1)">249</span> <span style="color: rgba(0, 0, 0, 1)">      directoryAndFilePaths.add(filePaths);
</span><span style="color: rgba(0, 128, 128, 1)">250</span>         <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> directoryAndFilePaths;
</span><span style="color: rgba(0, 128, 128, 1)">251</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">252</span>
<span style="color: rgba(0, 128, 128, 1)">253</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">254</span> <span style="color: rgba(0, 128, 0, 1)">   * 获取客户端文件夹下所有文件路径
</span><span style="color: rgba(0, 128, 128, 1)">255</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">256</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> List&lt;List&lt;String&gt;&gt;<span style="color: rgba(0, 0, 0, 1)"> getDirectoryUnderAllFile1(String path) {
</span><span style="color: rgba(0, 128, 128, 1)">257</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 存放目录和文件的路径</span>
<span style="color: rgba(0, 128, 128, 1)">258</span>         List&lt;List&lt;String&gt;&gt; directoryAndFilePaths = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">259</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 存放目录的路径</span>
<span style="color: rgba(0, 128, 128, 1)">260</span>         List&lt;String&gt; directoryPaths = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">261</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 存放文件的路径</span>
<span style="color: rgba(0, 128, 128, 1)">262</span>         List&lt;String&gt; filePaths = <span style="color: rgba(0, 0, 255, 1)">new</span> ArrayList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">263</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 待遍历处理的文件夹路径</span>
<span style="color: rgba(0, 128, 128, 1)">264</span>         Queue&lt;String&gt; ergodicDirPaths = <span style="color: rgba(0, 0, 255, 1)">new</span> LinkedList&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">265</span> <span style="color: rgba(0, 0, 0, 1)">      ergodicDirPaths.offer(path);
</span><span style="color: rgba(0, 128, 128, 1)">266</span> <span style="color: rgba(0, 0, 0, 1)">      directoryPaths.add(path);
</span><span style="color: rgba(0, 128, 128, 1)">267</span>
<span style="color: rgba(0, 128, 128, 1)">268</span>         <span style="color: rgba(0, 0, 255, 1)">while</span> (ergodicDirPaths.size() &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">269</span>             String entry =<span style="color: rgba(0, 0, 0, 1)"> ergodicDirPaths.poll();
</span><span style="color: rgba(0, 128, 128, 1)">270</span>
<span style="color: rgba(0, 128, 128, 1)">271</span>             File dir = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> File(entry);
</span><span style="color: rgba(0, 128, 128, 1)">272</span>             <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (File file : dir.listFiles()) {
</span><span style="color: rgba(0, 128, 128, 1)">273</span>               <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (file.isFile()) {
</span><span style="color: rgba(0, 128, 128, 1)">274</span>                     filePaths.add(entry + "/" +<span style="color: rgba(0, 0, 0, 1)"> file.getName());
</span><span style="color: rgba(0, 128, 128, 1)">275</span>               } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">276</span>                     directoryPaths.add(entry + "/" +<span style="color: rgba(0, 0, 0, 1)"> file.getName());
</span><span style="color: rgba(0, 128, 128, 1)">277</span>                     ergodicDirPaths.offer(entry + "/" +<span style="color: rgba(0, 0, 0, 1)"> file.getName());
</span><span style="color: rgba(0, 128, 128, 1)">278</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">279</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">280</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">281</span>
<span style="color: rgba(0, 128, 128, 1)">282</span> <span style="color: rgba(0, 0, 0, 1)">      directoryAndFilePaths.add(directoryPaths);
</span><span style="color: rgba(0, 128, 128, 1)">283</span> <span style="color: rgba(0, 0, 0, 1)">      directoryAndFilePaths.add(filePaths);
</span><span style="color: rgba(0, 128, 128, 1)">284</span>         <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> directoryAndFilePaths;
</span><span style="color: rgba(0, 128, 128, 1)">285</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">286</span>
<span style="color: rgba(0, 128, 128, 1)">287</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">288</span> <span style="color: rgba(0, 128, 0, 1)">   * 下载文件,若客户端已存在则覆盖它
</span><span style="color: rgba(0, 128, 128, 1)">289</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">290</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> download(String serverPath, String clientPath) {
</span><span style="color: rgba(0, 128, 128, 1)">291</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 判断服务端文件是否存在</span>
<span style="color: rgba(0, 128, 128, 1)">292</span>         FTPFile ftpFile =<span style="color: rgba(0, 0, 0, 1)"> getFTPFile(serverPath);
</span><span style="color: rgba(0, 128, 128, 1)">293</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpFile == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">294</span>             System.out.println("server file not exist"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">295</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">296</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">297</span>
<span style="color: rgba(0, 128, 128, 1)">298</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 若客户端目录不存在,就创建它,否则清空目录</span>
<span style="color: rgba(0, 128, 128, 1)">299</span>         File clientDirectory = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> File(clientPath);
</span><span style="color: rgba(0, 128, 128, 1)">300</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">clientDirectory.exists()) {
</span><span style="color: rgba(0, 128, 128, 1)">301</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">clientDirectory.mkdirs()) {
</span><span style="color: rgba(0, 128, 128, 1)">302</span>               System.out.println("client create directory fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">303</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">304</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">305</span>         } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">306</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">clientDirectory.isDirectory()) {
</span><span style="color: rgba(0, 128, 128, 1)">307</span>               System.out.println("clientPath is not directory"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">308</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">309</span>             } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">310</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">emptyDirectory(clientDirectory)) {
</span><span style="color: rgba(0, 128, 128, 1)">311</span>                     System.out.println("empty client directory fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">312</span>                     <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">313</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">314</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">315</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">316</span>
<span style="color: rgba(0, 128, 128, 1)">317</span>         <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (ftpFile.isFile()) {
</span><span style="color: rgba(0, 128, 128, 1)">318</span>             executeDownload(serverPath, clientPath + serverPath.substring(serverPath.lastIndexOf("/"<span style="color: rgba(0, 0, 0, 1)">)));
</span><span style="color: rgba(0, 128, 128, 1)">319</span>         } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">320</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">321</span>               List&lt;List&lt;String&gt;&gt; allFile =<span style="color: rgba(0, 0, 0, 1)"> getDirectoryUnderAllFile(serverPath);
</span><span style="color: rgba(0, 128, 128, 1)">322</span>               <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 获取所有目录路径</span>
<span style="color: rgba(0, 128, 128, 1)">323</span>               List&lt;String&gt; directoryPaths = allFile.get(0<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">324</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (directoryPaths.size() &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">325</span>                     directoryPaths.forEach(path -&gt; <span style="color: rgba(0, 0, 255, 1)">new</span> File(clientPath +<span style="color: rgba(0, 0, 0, 1)"> path).mkdir());
</span><span style="color: rgba(0, 128, 128, 1)">326</span>               } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">327</span>                     System.out.println("get all directory fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">328</span>                     <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">329</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">330</span>
<span style="color: rgba(0, 128, 128, 1)">331</span>               <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 获取所有文件路径</span>
<span style="color: rgba(0, 128, 128, 1)">332</span>               List&lt;String&gt; filePaths = allFile.get(1<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">333</span>               <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (String path : filePaths) {
</span><span style="color: rgba(0, 128, 128, 1)">334</span>                     executeDownload(path, clientPath +<span style="color: rgba(0, 0, 0, 1)"> path);
</span><span style="color: rgba(0, 128, 128, 1)">335</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">336</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">337</span>               System.out.println("error getting all files under this path"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">338</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">339</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">340</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">341</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">342</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">343</span>
<span style="color: rgba(0, 128, 128, 1)">344</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">345</span> <span style="color: rgba(0, 128, 0, 1)">   * 执行下载文件
</span><span style="color: rgba(0, 128, 128, 1)">346</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">347</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> executeDownload(String serverPath, String clientPath) {
</span><span style="color: rgba(0, 128, 128, 1)">348</span>         InputStream is = <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">349</span>         OutputStream os = <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">350</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">351</span>             is =<span style="color: rgba(0, 0, 0, 1)"> ftpClient.retrieveFileStream(clientCharsetToServer(serverPath));
</span><span style="color: rgba(0, 128, 128, 1)">352</span>             File file = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> File(clientPath);
</span><span style="color: rgba(0, 128, 128, 1)">353</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">file.createNewFile()) {
</span><span style="color: rgba(0, 128, 128, 1)">354</span>               System.out.println("client create file fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">355</span>               <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">356</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">357</span>             os = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> FileOutputStream(file);
</span><span style="color: rgba(0, 128, 128, 1)">358</span>             <span style="color: rgba(0, 0, 255, 1)">byte</span>[] by = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">byte</span>;
</span><span style="color: rgba(0, 128, 128, 1)">359</span>             <span style="color: rgba(0, 0, 255, 1)">int</span> len = 0<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">360</span>             <span style="color: rgba(0, 0, 255, 1)">while</span> ((len = is.read(by)) != -1) os.write(by, 0<span style="color: rgba(0, 0, 0, 1)">, len);
</span><span style="color: rgba(0, 128, 128, 1)">361</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">362</span>             System.out.println("stream handle file fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">363</span>             <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">364</span>         } <span style="color: rgba(0, 0, 255, 1)">finally</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">365</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">366</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (is != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">367</span> <span style="color: rgba(0, 0, 0, 1)">                  is.close();
</span><span style="color: rgba(0, 128, 128, 1)">368</span>                     <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 必须调用此方法,否则第二次调用retrieveFileStream()方法时,返回null</span>
<span style="color: rgba(0, 128, 128, 1)">369</span> <span style="color: rgba(0, 0, 0, 1)">                  ftpClient.completePendingCommand();
</span><span style="color: rgba(0, 128, 128, 1)">370</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">371</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (os != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) os.close();
</span><span style="color: rgba(0, 128, 128, 1)">372</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">373</span> <span style="color: rgba(0, 0, 0, 1)">                e.printStackTrace();
</span><span style="color: rgba(0, 128, 128, 1)">374</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">375</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">376</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">377</span>
<span style="color: rgba(0, 128, 128, 1)">378</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">379</span> <span style="color: rgba(0, 128, 0, 1)">   * 执行上传文件
</span><span style="color: rgba(0, 128, 128, 1)">380</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">381</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> executeUpload(String serverPath, String clientPath) {
</span><span style="color: rgba(0, 128, 128, 1)">382</span>         InputStream is = <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">383</span>         OutputStream os = <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">384</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">385</span>             is = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> FileInputStream(clientPath);
</span><span style="color: rgba(0, 128, 128, 1)">386</span>             os =<span style="color: rgba(0, 0, 0, 1)"> ftpClient.storeFileStream(clientCharsetToServer(serverPath));
</span><span style="color: rgba(0, 128, 128, 1)">387</span>
<span style="color: rgba(0, 128, 128, 1)">388</span>             <span style="color: rgba(0, 0, 255, 1)">byte</span>[] by = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">byte</span>;
</span><span style="color: rgba(0, 128, 128, 1)">389</span>             <span style="color: rgba(0, 0, 255, 1)">int</span> len = 0<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">390</span>             <span style="color: rgba(0, 0, 255, 1)">while</span> ((len = is.read(by)) != -1) os.write(by, 0<span style="color: rgba(0, 0, 0, 1)">, len);
</span><span style="color: rgba(0, 128, 128, 1)">391</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (FileNotFoundException e) {
</span><span style="color: rgba(0, 128, 128, 1)">392</span>             System.out.println("client file not found"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">393</span>             <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">394</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">395</span>             System.out.println("stream handle file fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">396</span>             <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">397</span>         } <span style="color: rgba(0, 0, 255, 1)">finally</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">398</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">399</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (is != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) is.close();
</span><span style="color: rgba(0, 128, 128, 1)">400</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (os != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">401</span> <span style="color: rgba(0, 0, 0, 1)">                  os.close();
</span><span style="color: rgba(0, 128, 128, 1)">402</span> <span style="color: rgba(0, 0, 0, 1)">                  ftpClient.completePendingCommand();
</span><span style="color: rgba(0, 128, 128, 1)">403</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">404</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">405</span> <span style="color: rgba(0, 0, 0, 1)">                e.printStackTrace();
</span><span style="color: rgba(0, 128, 128, 1)">406</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">407</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">408</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">409</span>
<span style="color: rgba(0, 128, 128, 1)">410</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">411</span> <span style="color: rgba(0, 128, 0, 1)">   * 上传文件,若服务端已存在则覆盖它
</span><span style="color: rgba(0, 128, 128, 1)">412</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">413</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> upload(String serverPath, String clientPath) {
</span><span style="color: rgba(0, 128, 128, 1)">414</span>         File clientFile = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> File(clientPath);
</span><span style="color: rgba(0, 128, 128, 1)">415</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (!<span style="color: rgba(0, 0, 0, 1)">clientFile.exists()) {
</span><span style="color: rgba(0, 128, 128, 1)">416</span>             System.out.println("client file not exist"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">417</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">418</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">419</span>
<span style="color: rgba(0, 128, 128, 1)">420</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (!"/"<span style="color: rgba(0, 0, 0, 1)">.equals(serverPath)) {
</span><span style="color: rgba(0, 128, 128, 1)">421</span>             FTPFile ftpFile =<span style="color: rgba(0, 0, 0, 1)"> getFTPFile(serverPath);
</span><span style="color: rgba(0, 128, 128, 1)">422</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpFile == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">423</span>               String[] split = serverPath.split("/"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">424</span>               changeWorkDirectory("/"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">425</span>               <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">426</span>                     <span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 1; i &lt; split.length; i++<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">427</span> <span style="color: rgba(0, 0, 0, 1)">                        ftpClient.makeDirectory(clientCharsetToServer(split));
</span><span style="color: rgba(0, 128, 128, 1)">428</span>                         changeWorkDirectory(getWorkDirectory() + "/" +<span style="color: rgba(0, 0, 0, 1)"> split);
</span><span style="color: rgba(0, 128, 128, 1)">429</span> <span style="color: rgba(0, 0, 0, 1)">                  }
</span><span style="color: rgba(0, 128, 128, 1)">430</span>               } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">431</span>                     System.out.println("create server directory error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">432</span>                     <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">433</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">434</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">435</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">436</span>
<span style="color: rgba(0, 128, 128, 1)">437</span>         serverPath = "/".endsWith(serverPath) ? ""<span style="color: rgba(0, 0, 0, 1)"> : serverPath;
</span><span style="color: rgba(0, 128, 128, 1)">438</span>         <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (clientFile.isFile()) {
</span><span style="color: rgba(0, 128, 128, 1)">439</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">440</span>               String filePath = serverPath + clientPath.substring(clientPath.lastIndexOf("/"<span style="color: rgba(0, 0, 0, 1)">));
</span><span style="color: rgba(0, 128, 128, 1)">441</span> <span style="color: rgba(0, 0, 0, 1)">                ftpClient.deleteFile(filePath);
</span><span style="color: rgba(0, 128, 128, 1)">442</span> <span style="color: rgba(0, 0, 0, 1)">                executeUpload(filePath, clientPath);
</span><span style="color: rgba(0, 128, 128, 1)">443</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">444</span>               System.out.println("delete server file error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">445</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">446</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">447</span>         } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">448</span>             List&lt;List&lt;String&gt;&gt; allFile =<span style="color: rgba(0, 0, 0, 1)"> getDirectoryUnderAllFile1(clientPath);
</span><span style="color: rgba(0, 128, 128, 1)">449</span>             List&lt;String&gt; directoryPaths = allFile.get(0<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">450</span> <span style="color: rgba(0, 0, 0, 1)">            String path2;
</span><span style="color: rgba(0, 128, 128, 1)">451</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (directoryPaths.size() &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">452</span>               <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">453</span>                     String firstDir = directoryPaths.get(0<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">454</span>                     String path1 = firstDir.substring(firstDir.lastIndexOf("/"<span style="color: rgba(0, 0, 0, 1)">));
</span><span style="color: rgba(0, 128, 128, 1)">455</span>                     path2 = firstDir.substring(0, firstDir.lastIndexOf("/"<span style="color: rgba(0, 0, 0, 1)">));
</span><span style="color: rgba(0, 128, 128, 1)">456</span>                     ftpClient.makeDirectory(clientCharsetToServer(serverPath +<span style="color: rgba(0, 0, 0, 1)"> path1));
</span><span style="color: rgba(0, 128, 128, 1)">457</span>                     <span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 1; i &lt; directoryPaths.size(); i++<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">458</span>                         String tempPath =<span style="color: rgba(0, 0, 0, 1)"> directoryPaths.get(i).substring(path2.length());
</span><span style="color: rgba(0, 128, 128, 1)">459</span>                         ftpClient.makeDirectory(clientCharsetToServer(serverPath +<span style="color: rgba(0, 0, 0, 1)"> tempPath));
</span><span style="color: rgba(0, 128, 128, 1)">460</span> <span style="color: rgba(0, 0, 0, 1)">                  }
</span><span style="color: rgba(0, 128, 128, 1)">461</span>               } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">462</span>                     System.out.println("create server directory error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">463</span>                     <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">464</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">465</span>             } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">466</span>               System.out.println("get all directory fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">467</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">468</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">469</span>             List&lt;String&gt; filePaths = allFile.get(1<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">470</span>             <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> (String path : filePaths) {
</span><span style="color: rgba(0, 128, 128, 1)">471</span>               String tempPath =<span style="color: rgba(0, 0, 0, 1)"> path.substring(path2.length());
</span><span style="color: rgba(0, 128, 128, 1)">472</span>               executeUpload(serverPath +<span style="color: rgba(0, 0, 0, 1)"> tempPath, path);
</span><span style="color: rgba(0, 128, 128, 1)">473</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">474</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">475</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">476</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">477</span>
<span style="color: rgba(0, 128, 128, 1)">478</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">479</span> <span style="color: rgba(0, 128, 0, 1)">   * 清空目录
</span><span style="color: rgba(0, 128, 128, 1)">480</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">481</span>   <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> emptyDirectory(File dir) {
</span><span style="color: rgba(0, 128, 128, 1)">482</span>         File[] oneLevelFile =<span style="color: rgba(0, 0, 0, 1)"> dir.listFiles();
</span><span style="color: rgba(0, 128, 128, 1)">483</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (oneLevelFile.length &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">484</span>             Stack&lt;File&gt; willDeleteFile = <span style="color: rgba(0, 0, 255, 1)">new</span> Stack&lt;&gt;<span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)">485</span>             <span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0; i &lt; oneLevelFile.length; i++<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">486</span> <span style="color: rgba(0, 0, 0, 1)">                willDeleteFile.push(oneLevelFile);
</span><span style="color: rgba(0, 128, 128, 1)">487</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">488</span>
<span style="color: rgba(0, 128, 128, 1)">489</span>             <span style="color: rgba(0, 0, 255, 1)">while</span> (willDeleteFile.size() &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">490</span>               File entry =<span style="color: rgba(0, 0, 0, 1)"> willDeleteFile.pop();
</span><span style="color: rgba(0, 128, 128, 1)">491</span>               <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (entry.isFile()) {
</span><span style="color: rgba(0, 128, 128, 1)">492</span>                     <span style="color: rgba(0, 0, 255, 1)">if</span> (!entry.delete()) <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">493</span>               } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">494</span>                     File[] lowerLevelFile =<span style="color: rgba(0, 0, 0, 1)"> entry.listFiles();
</span><span style="color: rgba(0, 128, 128, 1)">495</span>                     <span style="color: rgba(0, 0, 255, 1)">if</span> (lowerLevelFile.length &gt; 0<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">496</span> <span style="color: rgba(0, 0, 0, 1)">                        willDeleteFile.push(entry);
</span><span style="color: rgba(0, 128, 128, 1)">497</span>                         <span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 0; i &lt; lowerLevelFile.length; i++<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">498</span> <span style="color: rgba(0, 0, 0, 1)">                            willDeleteFile.push(lowerLevelFile);
</span><span style="color: rgba(0, 128, 128, 1)">499</span> <span style="color: rgba(0, 0, 0, 1)">                        }
</span><span style="color: rgba(0, 128, 128, 1)">500</span>                     } <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">501</span>                         <span style="color: rgba(0, 0, 255, 1)">if</span> (!entry.delete()) <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">502</span> <span style="color: rgba(0, 0, 0, 1)">                  }
</span><span style="color: rgba(0, 128, 128, 1)">503</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">504</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">505</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">506</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">507</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">508</span>
<span style="color: rgba(0, 128, 128, 1)">509</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">510</span> <span style="color: rgba(0, 128, 0, 1)">   * web端上传
</span><span style="color: rgba(0, 128, 128, 1)">511</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">512</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> webUpload(MultipartFile file, String serverPath) {
</span><span style="color: rgba(0, 128, 128, 1)">513</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (!"/"<span style="color: rgba(0, 0, 0, 1)">.equals(serverPath)) {
</span><span style="color: rgba(0, 128, 128, 1)">514</span>             FTPFile ftpFile =<span style="color: rgba(0, 0, 0, 1)"> getFTPFile(serverPath);
</span><span style="color: rgba(0, 128, 128, 1)">515</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpFile == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">516</span>               String[] split = serverPath.split("/"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">517</span>               changeWorkDirectory("/"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">518</span>               <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">519</span>                     <span style="color: rgba(0, 0, 255, 1)">for</span> (<span style="color: rgba(0, 0, 255, 1)">int</span> i = 1; i &lt; split.length; i++<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">520</span> <span style="color: rgba(0, 0, 0, 1)">                        ftpClient.makeDirectory(clientCharsetToServer(split));
</span><span style="color: rgba(0, 128, 128, 1)">521</span>                         changeWorkDirectory(getWorkDirectory() + "/" +<span style="color: rgba(0, 0, 0, 1)"> split);
</span><span style="color: rgba(0, 128, 128, 1)">522</span> <span style="color: rgba(0, 0, 0, 1)">                  }
</span><span style="color: rgba(0, 128, 128, 1)">523</span>               } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">524</span>                     System.out.println("create server directory error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">525</span>                     <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">526</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">527</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">528</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">529</span> <span style="color: rgba(0, 0, 0, 1)">      String filePath;
</span><span style="color: rgba(0, 128, 128, 1)">530</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">531</span>             serverPath = "/".endsWith(serverPath) ? ""<span style="color: rgba(0, 0, 0, 1)"> : serverPath;
</span><span style="color: rgba(0, 128, 128, 1)">532</span>             filePath = serverPath + "/" +<span style="color: rgba(0, 0, 0, 1)"> file.getOriginalFilename();
</span><span style="color: rgba(0, 128, 128, 1)">533</span> <span style="color: rgba(0, 0, 0, 1)">            ftpClient.deleteFile(filePath);
</span><span style="color: rgba(0, 128, 128, 1)">534</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">535</span>             System.out.println("delete server file error"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">536</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">537</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">538</span>
<span style="color: rgba(0, 128, 128, 1)">539</span>         InputStream is = <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">540</span>         OutputStream os = <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">541</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">542</span>             is =<span style="color: rgba(0, 0, 0, 1)"> file.getInputStream();
</span><span style="color: rgba(0, 128, 128, 1)">543</span>             os =<span style="color: rgba(0, 0, 0, 1)"> ftpClient.storeFileStream(clientCharsetToServer(filePath));
</span><span style="color: rgba(0, 128, 128, 1)">544</span>
<span style="color: rgba(0, 128, 128, 1)">545</span>             <span style="color: rgba(0, 0, 255, 1)">byte</span>[] by = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">byte</span>;
</span><span style="color: rgba(0, 128, 128, 1)">546</span>             <span style="color: rgba(0, 0, 255, 1)">int</span> len = 0<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">547</span>             <span style="color: rgba(0, 0, 255, 1)">while</span> ((len = is.read(by)) != -1) os.write(by, 0<span style="color: rgba(0, 0, 0, 1)">, len);
</span><span style="color: rgba(0, 128, 128, 1)">548</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (FileNotFoundException e) {
</span><span style="color: rgba(0, 128, 128, 1)">549</span>             System.out.println("client file not found"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">550</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">551</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">552</span>             System.out.println("stream handle file fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">553</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">554</span>         } <span style="color: rgba(0, 0, 255, 1)">finally</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">555</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">556</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (is != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) is.close();
</span><span style="color: rgba(0, 128, 128, 1)">557</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (os != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">558</span> <span style="color: rgba(0, 0, 0, 1)">                  os.close();
</span><span style="color: rgba(0, 128, 128, 1)">559</span> <span style="color: rgba(0, 0, 0, 1)">                  ftpClient.completePendingCommand();
</span><span style="color: rgba(0, 128, 128, 1)">560</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">561</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">562</span> <span style="color: rgba(0, 0, 0, 1)">                e.printStackTrace();
</span><span style="color: rgba(0, 128, 128, 1)">563</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">564</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">565</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">566</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">567</span>
<span style="color: rgba(0, 128, 128, 1)">568</span>   <span style="color: rgba(0, 128, 0, 1)">/**</span>
<span style="color: rgba(0, 128, 128, 1)">569</span> <span style="color: rgba(0, 128, 0, 1)">   * web端下载
</span><span style="color: rgba(0, 128, 128, 1)">570</span>      <span style="color: rgba(0, 128, 0, 1)">*/</span>
<span style="color: rgba(0, 128, 128, 1)">571</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">boolean</span><span style="color: rgba(0, 0, 0, 1)"> webDownload(HttpServletResponse response, String serverPath) {
</span><span style="color: rgba(0, 128, 128, 1)">572</span>         FTPFile ftpFile =<span style="color: rgba(0, 0, 0, 1)"> getFTPFile(serverPath);
</span><span style="color: rgba(0, 128, 128, 1)">573</span>         <span style="color: rgba(0, 0, 255, 1)">if</span> (ftpFile == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">574</span>             System.out.println("server file not exist"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">575</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">576</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">577</span>
<span style="color: rgba(0, 128, 128, 1)">578</span>         InputStream is = <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">579</span>         <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">580</span>             is =<span style="color: rgba(0, 0, 0, 1)"> ftpClient.retrieveFileStream(clientCharsetToServer(serverPath));
</span><span style="color: rgba(0, 128, 128, 1)">581</span>             ServletOutputStream sos =<span style="color: rgba(0, 0, 0, 1)"> response.getOutputStream();
</span><span style="color: rgba(0, 128, 128, 1)">582</span>             <span style="color: rgba(0, 0, 255, 1)">byte</span>[] by = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">byte</span>;
</span><span style="color: rgba(0, 128, 128, 1)">583</span>             <span style="color: rgba(0, 0, 255, 1)">int</span> len = 0<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">584</span>             <span style="color: rgba(0, 0, 255, 1)">while</span> ((len = is.read(by)) != -1) sos.write(by, 0<span style="color: rgba(0, 0, 0, 1)">, len);
</span><span style="color: rgba(0, 128, 128, 1)">585</span>         } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">586</span>             System.out.println("stream handle file fail"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">587</span>             <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">588</span>         } <span style="color: rgba(0, 0, 255, 1)">finally</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">589</span>             <span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">590</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (is != <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)">591</span> <span style="color: rgba(0, 0, 0, 1)">                  is.close();
</span><span style="color: rgba(0, 128, 128, 1)">592</span> <span style="color: rgba(0, 0, 0, 1)">                  ftpClient.completePendingCommand();
</span><span style="color: rgba(0, 128, 128, 1)">593</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">594</span>             } <span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (IOException e) {
</span><span style="color: rgba(0, 128, 128, 1)">595</span> <span style="color: rgba(0, 0, 0, 1)">                e.printStackTrace();
</span><span style="color: rgba(0, 128, 128, 1)">596</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">597</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">598</span>
<span style="color: rgba(0, 128, 128, 1)">599</span>         <span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">600</span> <span style="color: rgba(0, 0, 0, 1)">    }
</span><span style="color: rgba(0, 128, 128, 1)">601</span>
<span style="color: rgba(0, 128, 128, 1)">602</span> }</pre>
</div>
<span class="cnblogs_code_collapse">View Code</span></div><br><br>
来源:https://www.cnblogs.com/nearWind/p/12081260.html
頁: [1]
查看完整版本: linux搭建ftp服务器