我正在尝试将 FTP 服务器上的多个文件移动到同一服务器上的不同目录。到目前为止,我已经编写了一个 bash 脚本,它将登录并检索远程目录中的任何新文件,但 ftp 命令不支持“mv”命令。本质上,该脚本将下载新文件,然后下载后将文件移动到同一服务器上的不同目录。请注意,文件名每次都会不同,因此通配符的使用在这里很重要。
在您回答之前,请注意这需要自动化,因此使用像 Filezilla 这样的 GUI 对我没有帮助,因为我必须登录到各种 ftp 站点并手动移动文件,另外,请记住,我无法通过 ssh 访问任何服务器,因为它们是由其他公司管理的,并且我只能进行 ftp 访问。最后一件事,我不知道文件名是什么,因此使用通配符会很有帮助。
非常感谢任何帮助或指导。
谢谢!
最佳答案
也许 ftp 中的重命名命令适合您?
rename [from [to]]
Rename the file from on the remote machine, to the file to.
我用服务器上的一个旧文件对它进行了 bash ,它似乎做了你想要的事情:
ftp> ls tmp/test*
229 Entering Extended Passive Mode (|||55572|)
150 Accepted data connection
-rw-r--r-- 1 sinasohn sinasohn 21 Mar 31 16:37 tmp/testfile01
226-Options: -a -l
226 1 matches total
ftp> ls tmp2/test*
229 Entering Extended Passive Mode (|||64715|)
150 Accepted data connection
226-Options: -a -l
226 0 matches total
ftp> rename tmp/testfile01 tmp2/testfile01
350 RNFR accepted - file exists, ready for destination
250 File successfully renamed or moved
ftp> ls tmp/test*
229 Entering Extended Passive Mode (|||56698|)
150 Accepted data connection
226-Options: -a -l
226 0 matches total
ftp> ls tmp2/test*
229 Entering Extended Passive Mode (|||50239|)
150 Accepted data connection
-rw-r--r-- 1 sinasohn sinasohn 21 Mar 31 16:37 tmp2/testfile01
226-Options: -a -l
226 1 matches total
ftp>
为了清楚起见,我在命令之间放置了空行。
希望这有帮助!
关于bash - 编写在 FTP 服务器上移动文件的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43149929/