LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron FTP get and delete (https://www.linuxquestions.org/questions/linux-newbie-8/cron-ftp-get-and-delete-610080/)

dreammold 12-31-2007 02:52 AM

Cron FTP get and delete
 
Hey everyone I need a little help here. I want to setup a cron that will do 3 things.
1) It will connect via ftp to a server and download a file called games.log
2) Then delete the source games.log from the ftp site after the download finished.
3) Then run this command line shell
php vsp.php -l wet "/public_html/wet/games.log"

Can someone please help me out with this?

MS3FGX 12-31-2007 03:44 AM

Does it have to use FTP?

I ask because FTP is rather difficult to script as there is no way to control it via command line switches, it needs to be controlled interactively as if you were sitting there typing commands into it.

In contrast, if you could use some mountable network filesystem (NFS, SSH, etc) then you can mount the remote machine and operate on the files as if they were local.

Not to say doing it over FTP isn't possible, it will just be harder. I have certainly never been able to script the functionality I have wanted when using an interactive FTP client, at least.

jschiwal 12-31-2007 06:07 AM

You could call the ftp command like:

Call it like
ftp user:password@host << EOF
get games.log
del games.log
bye
EOF

ghostdog74 12-31-2007 06:10 AM

Quote:

Originally Posted by MS3FGX (Post 3006428)
Does it have to use FTP?

I ask because FTP is rather difficult to script as there is no way to control it via command line switches, it needs to be controlled interactively as if you were sitting there typing commands into it.

Not really
Code:

ftp -n ftp.server.com << EOF 
user anonymous anonymous@gmail.com
get games.log
delete games.log
bye
EOF


frenchn00b 12-31-2007 07:36 AM

Code:

man wget
/ftp ENTER
n
n
n
...

I d bet it can download from the ftp

Code:

man tail
was swiftly

MS3FGX 12-31-2007 08:43 AM

Quote:

You could call the ftp command like:

Call it like
ftp user:password@host << EOF
get games.log
del games.log
bye
EOF
The problem with this, at least in my experience, is that it works fine as long as everything goes according to plan. It is difficult to accurately catch and handle errors in this scenario since the script can't interact with the FTP client itself, and is just sending canned messages to it.

For example, if we could call an ftp client with commands like:

Code:

ftp user:password@host -get games.log
ftp user:password@host -del games.log

We could easily trap errors by checking the return value it gives back for each step; but when you just throw commands at the client, there is no way to tell were an error occurred so that it can be handled gracefully.

frenchn00b 12-31-2007 11:39 AM

In man wget, I got this. This may maybe interest you.

Code:

  wget -c ftp://sunsite.doc.ic.ac.uk/ls-lR.Z
Code:

Specify the username user and password password for both FTP and
          HTTP file retrieval.  These parameters can be overridden using the
          --ftp-user and --ftp-password options for FTP connections and the
          --http-user and --http-password options for HTTP connections.



All times are GMT -5. The time now is 01:11 AM.