LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-09-2013, 09:21 AM   #1
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Rep: Reputation: Disabled
FTP File script (from one server to another)


I am looking to ftp a log file from one server to another, I want to be able to set this up in a file so I can run it at certain times with cron so I don't have to log on and ftp the file over.

something like:

ftp 192.168.1.*
root
*******
bin
lcd /appl/ai
cd /appl/ai/Simple_1_AI
mput ai.log
quit
 
Old 10-09-2013, 10:04 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
look into scp (with public key encryption) to set up an automated file transfer.
 
Old 10-09-2013, 02:47 PM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
if FTP is the ONLY way to move it, see above scp or rysnc would be far better/secure with use of keys, then you have 2 choices.

1. hand populate the user/pw into the script that calls ftp to move the file from server A to B. insecure due to plane text user/pw for FTP access directly in the script.

2. use expect. this does basically the same thing as hard coding the user/pw into the script and will send the user/pw in plane text via the WWW so also not secure, but does put the user/pw into a different file, sadly still in plane text.

Code:
#!/bin/bash

USER=user
PASS=password
URL=destination_server_IP
DEST=/path/on/remote/server/to/put/log/file/
DATE="`date +%Y-%m-%d-%H.%M.%S `"
LOG=/path/to/log/${DATE}-FTP.log
FILE=/path/to/file/to/transmit/foo.log

     echo "starting FTP transfer of ${FILE} at ${DATE}." >> ${LOG}
     lftp -e "set ftp:passive-mode on && cd ${DEST} && put ${FILE} && bye" -u ${USER},${PASS} ${URL}
     echo "end of FTP transfer at ${DATE}." >> ${LOG}

exit
that is a very very very basic lftp script for you. modify as you need and enjoy.
 
Old 10-11-2013, 04:46 PM   #4
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
I am not looking for anything high tech or security, the servers are right next to each other (well in the same building).

I can
ssh IP (and no login is needed becasue of ssh keys)
telnet IP (login is needed)
ftp IP (login is needed)

is there a command I can run with ssh similair to ftp "put" and "get"?

ssh 192.*.*.* (this would be the backup servers IP address)
cd /appl/ai/test
put ai.log #ai.log would be on the primary server)
exit


or


what would a "scp" command be to transfer my /appl/ai/ai.log file to 192.*.*.* /appl/ai/test
that I could set up in cron to run

.

Last edited by T-Dub116; 10-11-2013 at 04:50 PM.
 
Old 10-12-2013, 10:20 AM   #5
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 962
Blog Entries: 3

Rep: Reputation: 393Reputation: 393Reputation: 393Reputation: 393
sftp in batch mode

Quote:
Originally Posted by T-Dub116 View Post
is there a command I can run with ssh similair to ftp "put" and "get"?
If you are connecting with keys then you can use sftp(1) in batch mode. See the manual page for sftp(1) for details, the option you are looking for is -b It should point to a text file containing all the sftp interactive commands (lcd, put, get, exit, etc) that you wish to run.

BTW if you've been using telnet or ftp to log in with a username and password, it would be a good idea to change passwords and then disable the ftp and telnet services.
 
Old 10-12-2013, 01:30 PM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Quote:
Originally Posted by T-Dub116 View Post
I am not looking for anything high tech or security, the servers are right next to each other (well in the same building).

I can
ssh IP (and no login is needed becasue of ssh keys)
telnet IP (login is needed)
ftp IP (login is needed)

is there a command I can run with ssh similair to ftp "put" and "get"?

ssh 192.*.*.* (this would be the backup servers IP address)
cd /appl/ai/test
put ai.log #ai.log would be on the primary server)
exit


or


what would a "scp" command be to transfer my /appl/ai/ai.log file to 192.*.*.* /appl/ai/test
that I could set up in cron to run

.
if you can ssh, then see the links in my sig for setting up keys, then you can just scp or rsync the log file via ssh. the nice thing about keys is they are very simple to script as you will be connecting passwordless.

after you setup the passwordless connection (ssh keys) you can modify my lftp script and replace the lines with something as follows:

Code:
    rsync -aviS /path/to/local/file.log ${RUSER}@${URL}:/path/to/put/file.log

or

    scp /path/to/local/file.log ${RUSER}@${URL}:/path/to/put/file.log
in short both rsync and scp will, in this case, do the same thing. hit up the man pages to learn the difference between scp and rsync, but with a single file it is the same result.

just an FYI, if the log file is very large rsync will be lighter on the server then scp, this is the reason i prefer rsync over scp.

Last edited by lleb; 10-12-2013 at 01:34 PM.
 
1 members found this post helpful.
Old 10-12-2013, 02:20 PM   #7
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 872

Rep: Reputation: 112Reputation: 112
Here is a simple ftp script you should be able to edit to your need
Code:
#!/usr/bin/sh

file = <your_file_t0_move>
host = <your_ftp_host>
port = <ftp_port usually 21>
user = < ftp_user>
pass = <ftp_user_password>

ftp -inv $host $port << EOF
use $ user $pass
put $file
bye
EOF
Its not the best script but you can make it work, Besure to move the brackets and put in your info like "host = ftp.hostnetwork.cxm"

good luck
 
1 members found this post helpful.
Old 10-14-2013, 03:37 PM   #8
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
[QUOTE=lleb;5044523]

scp /path/to/local/file.log ${RUSER}@${URL}:/path/to/put/file.log[/code]




Thank You, I got this to work:

scp /appl/ai/ai.log root@backup:/appl/ai/Simple_1_AI/ai.log
 
  


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
How can i download a file from remote server using ftp using shell script sanjay87 Linux - Server 10 04-16-2012 07:09 AM
[SOLVED] Make FTP script to upload file to server? mvmacd Linux - Newbie 5 12-31-2009 01:33 PM
In plesk , I wish to have a backup cron job, ftp back up file to another ftp server? muskiediver Linux - General 6 07-16-2009 04:13 AM
Need script to dump database, ftp file to backup server glock19 Linux - Networking 17 05-12-2003 06:56 PM


All times are GMT -5. The time now is 06:26 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