ANT 远程发布到FTP服务器的方法

在ANT中用FTP脚本

<ftp action="put" password="其他电脑密码" remotedir="其他电脑共享目录" server="其他电脑IP地址" userid="其他电脑用户名">
      <fileset file="需要上传的文件"/>
</ftp>

 

action="put" 表明上传  action="get" 表明下载


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要通过Java实现FTP远程解压缩文件,可以采用以下的步骤: 1. 连接FTP服务器,使用FTPClient类实现。 2. 切换到需要解压缩的目录下,使用FTPClient.changeWorkingDirectory()方法。 3. 下载需要解压缩的压缩文件到本地,使用FTPClient.retrieveFile()方法。 4. 解压缩文件,可以使用Java的ZipInputStream或者Apache Ant的Zip类库。 5. 将解压后的文件上传到FTP服务器上,使用FTPClient.storeFile()方法。 下面是一个简单的示例代码: ```java import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class FtpUnzipDemo { public static void main(String[] args) throws IOException { String server = "ftp.example.com"; int port = 21; String username = "username"; String password = "password"; String remoteDir = "/remote/dir"; String remoteFile = "file.zip"; String localDir = "/local/dir"; FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(server, port); ftpClient.login(username, password); ftpClient.changeWorkingDirectory(remoteDir); File localFile = new File(localDir, remoteFile); OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localFile)); ftpClient.retrieveFile(remoteFile, outputStream); outputStream.close(); unzip(localFile, new File(localDir)); FTPFile[] files = ftpClient.listFiles(); for (FTPFile file : files) { if (file.isFile()) { InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(localDir, file.getName()))); ftpClient.storeFile(file.getName(), inputStream); inputStream.close(); } } ftpClient.logout(); } finally { if (ftpClient.isConnected()) { ftpClient.disconnect(); } } } private static void unzip(File zipFile, File destDir) throws IOException { byte[] buffer = new byte[1024]; ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { File newFile = new File(destDir, zipEntry.getName()); if (zipEntry.isDirectory()) { newFile.mkdirs(); } else { FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); } zipEntry = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } } ``` 注意事项: 1. 要使用Apache Commons Net类库实现FTP连接和文件传输。 2. 要保证FTP服务器上的压缩文件格式与Java程序中解压缩的方式一致,例如都是ZIP格式。 3. 要注意FTP服务器上的文件路径格式和本地文件路径格式的区别,例如FTP服务器上使用“/”作为路径分隔符,而Windows本地文件系统使用“\”作为路径分隔符。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值