Automate ftp upload to ip

2020-08-02 11:42发布

问题:

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

回答1:

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



回答2:

The magic keyword is crontab.

  • http://linuxwiki.de/crontab


回答3:

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



标签: upload ftp ip