ftp自动推送-linux

#!/bin/bash
yum -y install ftp
if [ $? -eq 0 ];then
cat >> /root/push.sh << EOF
#!/bin/sh
ServerIP=""
USER=""
USER_PW=""
#Put_File=""
Put_dir=""
Local_dir=""
ftp -n $ServerIP <<End-Of-Session #标记符号
user $USER $USER_PW
cd $Put_dir #进入到目的服务器的相应目录
lcd $Local_dir #进入到本地目录
binary  # 二进制文件格式传送
put $Put_File #传送文件
bye #结束会话
EOF
else
  echo "ftp-client安装失败"
fi

客户端关闭被动

passive

 

开启被动模式

pasv_enable=YES
pasv_min_port=21
pasv_max_port=21
pasv_address=0.0.0.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Spring Boot中实现FTP推送,你需要使用一个FTP客户端库,如Apache Commons Net或Spring Integration FTP。下面是一个使用Apache Commons Net的示例代码: 1. 首先,在你的Maven或Gradle项目中添加Apache Commons Net的依赖: Maven: ``` <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.6</version> </dependency> ``` Gradle: ``` compile group: 'commons-net', name: 'commons-net', version: '3.6' ``` 2. 创建一个FTP客户端类,用于连接FTP服务器和上传文件: ``` import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class FtpClient { @Value("${ftp.server}") private String server; @Value("${ftp.port}") private int port; @Value("${ftp.username}") private String username; @Value("${ftp.password}") private String password; public void uploadFile(File file, String remoteDir) throws IOException { FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(server, port); ftpClient.login(username, password); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); String remoteFile = remoteDir + "/" + file.getName(); FileInputStream inputStream = new FileInputStream(file); boolean uploaded = ftpClient.storeFile(remoteFile, inputStream); if (uploaded) { System.out.println("File uploaded successfully."); } else { System.out.println("File upload failed."); } } finally { ftpClient.logout(); ftpClient.disconnect(); } } } ``` 3. 在你的应用程序中使用FtpClient类来上传文件: ``` @Autowired private FtpClient ftpClient; public void pushFileToFTP() { File file = new File("path/to/local/file"); String remoteDir = "/path/to/remote/directory"; try { ftpClient.uploadFile(file, remoteDir); } catch (IOException e) { e.printStackTrace(); } } ``` 这样,你就可以在Spring Boot应用程序中使用FTP客户端库来实现文件推送FTP服务器。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值