LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2009, 07:11 AM   #1
alanbo
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
Question 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
 
Old 03-17-2009, 07:13 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Hi,

Take a look at
Code:
ncftpput
man ncftpput
 
Old 03-17-2009, 05:42 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
since ftp was designed to prompt the user for input, i would recommend scp.
 
Old 03-17-2009, 10:27 PM   #4
JaksoDebr
Member
 
Registered: Mar 2009
Distribution: Fedora, Slackware
Posts: 104

Rep: Reputation: 21
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

Last edited by JaksoDebr; 04-02-2009 at 06:04 AM.
 
Old 03-17-2009, 10:38 PM   #5
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,200

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
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
 
Old 03-17-2009, 10:39 PM   #6
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,970
Blog Entries: 1

Rep: Reputation: 208Reputation: 208Reputation: 208
Quote:
Originally Posted by alanbo View Post
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
 
Old 03-18-2009, 03:07 AM   #7
ryannlinux
LQ Newbie
 
Registered: Feb 2009
Location: NZ
Distribution: Ubuntu
Posts: 9

Rep: Reputation: 0
#!/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?
 
Old 03-18-2009, 04:44 AM   #8
alanbo
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there an ftp program that allows for multi-thread ftp uploads ? Want faster upload brjoon1021 Linux - Software 4 02-04-2009 07:28 PM
FTP UPload! nooni Linux - Newbie 3 03-15-2008 04:20 PM
FTP upload hinetvenkat Linux - Software 3 06-02-2005 10:34 PM
Cant upload to another FTP brandog Linux - Software 1 05-03-2003 03:47 PM
cronjob for auto-ftp bktpv Linux - Networking 2 12-08-2001 08:30 AM


All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration