LinuxQuestions.org
Latest LQ Deal: Linux Power User 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 08-30-2008, 08:33 PM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
automatic sending of files thru ftp.


Hi,

I keep sending few regular files(which are in different directory) to my higher office thru ftp. Every time i login that ftp server by using ftp command mput the required files. I want a code to send these files automatically. I am new to sys administration.

ex: my higher office ftp server id suppose : 10.10.10.10 (we defined this in the hosts file as higher)
user name is : comin
password : weldone

kindly give a shell script and explain me if possible.
 
Old 08-30-2008, 08:38 PM   #2
firekool
LQ Newbie
 
Registered: May 2007
Posts: 1

Rep: Reputation: 0
Just a note you may not want to post username and passwords on the net.
 
Old 08-30-2008, 08:53 PM   #3
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
that is not real user name and real password and even ip is not that tooo...
 
Old 09-06-2008, 02:03 PM   #4
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Hello anybody is there?
 
Old 09-06-2008, 04:00 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can pass commands to ftp through standard input. In a script you will end up with a here document. For example:
Code:
/usr/bin/ftp -ni 10.10.10.10 <<-EOS
    user comin weldone
    binary
    cd /path/to/remote/directory
    mput $files
    bye
EOS
You can put every permitted ftp command inside the here document. In my example I used the user command to login. The binary command to ensure a correct transfer of all types of files, the cd command to go to the directory where you want to upload, the mput statement and the bye command to quit politely.

In a here document you can put shell variables or command substitutions to manage dynamic data. The shell will expand them before actually execute the ftp commands. Regarding the ftp option, I usually put -n to avoid the automatic login through the .netrc file (if any) and the -i option to prevent interactive prompting. This happens when you transfer multiple files and the ftp asks you confirmation about every file (in alternative you can use the prompt command to toggle the interactive prompting on and off).

A security concern is that in this kind of script you have to write username and password in clear text. If someone with malicious intent has access to your script, he can do some damage to the remote server.

Hope this helps. See also man ftp for future reference.

Last edited by colucix; 09-06-2008 at 04:02 PM.
 
Old 09-07-2008, 08:00 AM   #6
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Thank you colucix. I hav some more queries..

1. Here user name is comin and password is weldone ... am i right?

2. I want to send some files after bzipping and after sending the zipped files to be unzipped automatically. How?

3. Is there any other script which will not show the password?
 
Old 09-07-2008, 09:05 AM   #7
niceguy_81333
Member
 
Registered: Mar 2008
Location: India
Distribution: RHEL5
Posts: 34

Rep: Reputation: 15
The complete code looks as follows(using the above code)

$echo "Please enter the directory you want to upload"
read $ftpdir
cd $ftpdir
bzip2 $ftpdir

/usr/bin/ftp -ni 10.10.10.10 <<-EOS
user comin weldone
binary
cd /path/to/remote/directory
mput $ftpdir
bye
EOS

bunzip2 $ftpdir.bz2

Last edited by niceguy_81333; 09-07-2008 at 09:08 AM.
 
Old 09-08-2008, 12:10 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
To avoid the usr/passwd issue you could use scp or sftp (both part of the ssh install) with the authorised keys method.
 
Old 09-09-2008, 09:06 AM   #9
smehra24
Member
 
Registered: Jan 2008
Location: mumbai
Distribution: red hat
Posts: 31

Rep: Reputation: 15
Quote:
Originally Posted by niceguy_81333 View Post
The complete code looks as follows(using the above code)

$echo "Please enter the directory you want to upload"
read $ftpdir
cd $ftpdir
bzip2 $ftpdir

/usr/bin/ftp -ni 10.10.10.10 <<-EOS
user comin weldone
binary
cd /path/to/remote/directory
mput $ftpdir
bye
EOS

bunzip2 $ftpdir.bz2
It Works .... .... ..
 
  


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
Automatic FTP Backup aquaboot Linux - Software 5 06-03-2006 07:34 PM
Automatic ftp using cron problem giteshtrivedi Linux - General 4 04-22-2006 12:26 PM
Automatic FTP greatmenon Linux - Software 1 01-20-2006 11:09 PM
FTP - remote login (automatic?) claudiascotti Linux - Networking 4 05-23-2005 04:14 PM
Automatic email sending with sendmail? Stingreen Linux - General 10 04-15-2002 03:55 PM


All times are GMT -5. The time now is 02:52 AM.

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