LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Ftp upload cronjob (https://www.linuxquestions.org/questions/linux-newbie-8/ftp-upload-cronjob-712220/)

alanbo 03-17-2009 06:11 AM

Ftp upload cronjob
 
Hi, i'm a fairly basic linux users so excuse any stupidity :)

I was wondering if anyone might be able to help me out in locating a single file ftp script.

What i want to do is:

- XML file
- Connect to ftp
- Upload xml file
- Replace if file already exists

- Cronjob every 5 minutes


So basically upload a single file called "myfile.xml" to my server (which is a webserver) via ftp via a cronjob from a linux machine/server. When its uploading it will need to replace the file that was previously there.

Is there anything easily obtainable for this?

Thanks for anyone who might be able to help out.

Regards

Alan

repo 03-17-2009 06:13 AM

Hi,

Take a look at
Code:

ncftpput
man ncftpput


schneidz 03-17-2009 04:42 PM

since ftp was designed to prompt the user for input, i would recommend scp.

JaksoDebr 03-17-2009 09:27 PM

You should read a manual on SSH and how to install authentication keys on the server to allow actions without human interaction (login). 'scp' is basically a wrapper for SSH to transfer data to/from remote locations. With authentication in place, your cron script would have something like:
Quote:

scp localfile remoteuser@remotehost:
(The colon at the tail is important).

JD

Linux Archive

frieza 03-17-2009 09:38 PM

if it HAS to be ftp you could simply create a php script
Code:

<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';
$ftp_server="server";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
$ftp_user_name="username";
$ftp_user_pass="password";
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

of course php would have to be installed
then simply tell the cron job to run 'php myscript.php' every 5 minutes

custangro 03-17-2009 09:39 PM

Quote:

Originally Posted by alanbo (Post 3478120)
Hi, i'm a fairly basic linux users so excuse any stupidity :)

I was wondering if anyone might be able to help me out in locating a single file ftp script.

What i want to do is:

- XML file
- Connect to ftp
- Upload xml file
- Replace if file already exists

- Cronjob every 5 minutes


So basically upload a single file called "myfile.xml" to my server (which is a webserver) via ftp via a cronjob from a linux machine/server. When its uploading it will need to replace the file that was previously there.

Is there anything easily obtainable for this?

Thanks for anyone who might be able to help out.

Regards

Alan

What about...
Code:

#!/bin/bash
 ftp -i -n ${ftphost} <<-EOF
        user ${ftpuser} ${ftppasswd}
        lcd "${localfiledir}"
        cd "${ftpdir}"
        bi
        put "${filename}"
        bye
        EOF


ryannlinux 03-18-2009 02:07 AM

#!/bin/bash
rsync localfile user@remotebox:/usr/data/

I'm partly suggesting and asking, I think rsync will make the task more simple, comments please?

alanbo 03-18-2009 03:44 AM

Cheers guys there are definatly some goo options here for me to takke, the php mentod might actually be the best option for me as i am familiar with this however custangros solution looks like another good one for me as i can kinda understand that.

Once again thanks guys. I really appreciate your help.


All times are GMT -5. The time now is 04:24 AM.