Automate ftp upload to ip

2020-08-02 11:14发布

Is there a way to automate an upload of files from my local dekstop to an external ip address?

Maybe I can write a program in Java/C# that transfers my files from my local desktop to an external Ip and schedule that program every day for exemple??

Is this possible?

Thx

标签: upload ftp ip
3条回答
Bombasti
2楼-- · 2020-08-02 11:39

Since you don't specify your OS, am going to assume a Standard OS (*nix), so you could proceed like this:

Create a Bash script (say myuploads.sh), and in it, you'll automate the uploading of the files of interest to the remote machine. Something like this:

#!/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

U 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

查看更多
Explosion°爆炸
3楼-- · 2020-08-02 11:52

The magic keyword is crontab.

查看更多
混吃等死
4楼-- · 2020-08-02 12:02

You mention C#, so for the windows system, place the ftp commands in a file:

user 
<your name>
<your password>
cd pub
bin
mput *
quit

and schedule a job to run ftp -n -s:cmd.file 127.0.0.1

查看更多
登录 后发表回答