使用file.sh将CSV文件从sftp服务器传输到ftp服务器

时间:2019-08-20 04:01:37

标签: ftp sh sftp centos7

我正在设置cron作业,在cronjob.sh中,我需要将csv文件从服务器sftp传输到ftp服务器,有什么想法或解决办法吗?

1 个答案:

答案 0 :(得分:0)

首先编写一个完成该任务的Shell脚本(.sh)文件。

假设两个服务器都是启用了scp的linux节点,请尝试这样的bash脚本:

#!/bin/bash
# we assume ssh gen-rsa is used to generate id_rsa_1 and id_rsa_2 
# for username1 and username2 for host1 and host2 respectively.

cd /path/to/id_rsa/files
# download the file
scp -i id_rsa_1 usename1@host1:/path/to/your/csv/file.csv ./
# upload the file
scp -i id_rsa_2 ./file.csv username2@host2:/path/to/destination/directory/

以上内容可以通过命令行运行为:

chmod 755 my_bash.sh
./my_bash.sh

验证文件传输是否正常。

然后,在crontab -e编辑器中调用my_bash.sh。