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

Tranfer csv file from sftp server to ftp server using file.sh

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

首先编写一个 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。