自动将 FTP 上传到 IP 地址 [英] Automate FTP upload to an IP address
问题描述
有没有办法自动将文件从我的本地桌面上传到外部 IP 地址?
Is there a way to automate an upload of files from my local desktop to an external IP address?
也许我可以用 Java/C# 编写一个程序,例如将我的文件从本地桌面传输到外部 IP 地址并每天安排该程序?
Maybe I can write a program in Java/C# that transfers my files from my the local desktop to an external IP address and schedule that program every day for example?
这可能吗?
推荐答案
由于你没有指定你的操作系统,我将假设一个标准操作系统 (*nix),所以你可以继续像这样:
Since you don't specify your OS, I am going to assume a standard OS (*nix), so you could proceed like this:
创建一个 Bash 脚本(比如 myuploads.sh
),并在其中自动将感兴趣的文件上传到远程机器.
Create a Bash script (say myuploads.sh
), and in it, you'll automate the uploading of the files of interest to the remote machine.
像这样:
#!/bin/bash
HOST='1.2.5.7'
USER='us3r'
PASSWD='p4ssword'
FILE_TO_UPLOAD='/path/to/some_file.some'
WHERE_TO_UPLOAD='/remote/path'
ftp -i -n $HOST <<Arul
user ${USER} ${PASSWD}
binary
cd $(WHERE_TO_UPLOAD)
put $(WHERE_TO_UPLOAD)
quit
然后,您可以使用标准 cron(作业调度程序)来安排何时定期上传该文件,例如使用这样的 cron 条目:
You can then use a standard cron (job scheduler) to schedule when to periodically upload that file, using say a cron entry like this:
@daily /path/to/script/myuploads.sh >/dev/null
每天午夜运行一次脚本.
That runs the script once every day at midnight.
这篇关于自动将 FTP 上传到 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!