LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-06-2008, 11:49 AM   #1
X-Rayden
LQ Newbie
 
Registered: May 2008
Posts: 17

Rep: Reputation: 0
How to use ftp or pftp in a bash file?


I'm difinitely not an expert on bash files, but i know my way around, create daily backup or rsync with a cronjob, but i've NEVER used ftp or pftp on linux and frankly i'm at a lost.

I can't even work out a manual ftp connection, but my goal is to bash it.

i've got a dedicated server for youtube like experimentation and it does a backup every morning of the database and stuff (other than videos).

I rsync it on a local computer every noon but i'd like to use a low price / lot of space shared hosting like powweb to dump the daily backup, but it dont use ssh so i'll have to use FTP to do it.

I can connect like this :

Code:
pftp votreespace.net
Connected to someserver.net (75.126.XXX.XXX).
220---------- Welcome to Pure-FTPd [TLS] ----------
220-You are user number 3 of 50 allowed.
220-Local time is now 11:41. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 80 minutes of inactivity.
Unknown .netrc keyword Johnny
Unknown .netrc keyword *********
Unknown .netrc keyword someserver.net
Name (someserver.net:root): Johnny
331 User Johnny OK. Password required
Password:
230-User Johnny has group access to:  Johnny
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quit
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.
i figured out how to connect... but not automaticly with the .netrc cause i can't seam to figure this out ?

i want it to autoconnect to the ftp, upload a file and disconnect within this bash file :

Code:
date=$(date +'%F')
set -- $date
mkdir /var/backups
tar -cjvf /var/BACKUPS/backup.$date.tar.bz2 --exclude /var/www/html/videos.sportsmotorises.com/uploads 
--exclude /var/www/html/videos.yournetspace.ca/uploads /var/www /var/log /var/lib/mysql /etc/httpd /etc/php.ini /etc/php.d
*** connect to ftp
*** go to repertory i want
*** upload /var/BACKUPS/backup.$date.tar.bz2
*** disconnect
is that even possible ?

Last edited by X-Rayden; 08-09-2008 at 12:35 PM.
 
Old 08-07-2008, 06:55 AM   #2
sleepyhomme
LQ Newbie
 
Registered: Jan 2006
Posts: 28

Rep: Reputation: 15
you can do something like this by bash scripting.

Code:
#!/bin/bash
cd $HOME/foo/bar
HOST='www.*.com'
USER='********'
PASSWD='*******'

ftp -n -v $HOST << EOT
binary
user $USER $PASSWD
prompt
cd foo/bar
put the_file_you_want.txt
mkdir linux
cd linux
put testing1.x
bye
EOT
The main disadvantage is that you have to hard code the user name and password in your script file.

But you can harden your FTP server (my preferred one is vsftpd) by chrooting the connecting user and granting LEAST access to it.

Hope this helps! Cheers
 
Old 08-07-2008, 09:02 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Just an aside note: you have posted the IP address of a server, a valid username and a 9 characters long password. Not really secure. Better to put XX.XX.XX.XX in place of the address and use a dummy username. You never know...!
 
Old 08-08-2008, 09:03 AM   #4
X-Rayden
LQ Newbie
 
Registered: May 2008
Posts: 17

Original Poster
Rep: Reputation: 0
i've modified the output to dummy stuff, it's my job to be secure, I dont think i'd be that careless!

hehe thanks sleepyhomme, i'll try that!
 
Old 08-08-2008, 09:07 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by X-Rayden View Post
i've modified the output to dummy stuff, it's my job to be secure, I dont think i'd be that careless!
So you redirect potential attacks to another random server?
 
Old 08-08-2008, 02:01 PM   #6
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
why not use ncftpput?
 
Old 08-08-2008, 11:19 PM   #7
sleepyhomme
LQ Newbie
 
Registered: Jan 2006
Posts: 28

Rep: Reputation: 15
that's another choice.
 
Old 08-09-2008, 12:33 PM   #8
X-Rayden
LQ Newbie
 
Registered: May 2008
Posts: 17

Original Poster
Rep: Reputation: 0
first time in my life i've hear about ncftpput

is it easier? faster ? more secure ?
 
Old 08-09-2008, 12:50 PM   #9
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
easier:
once you figure out the command options you want, then yes it's quite simple. some examples from its man page:

ncftpput -a -u gleason -p my.password -m -U 007 Bozo.probe.net /tmp/tmpdir a.txt
tar cvf - /home | ncftpput -u operator -c Server.probe.net /backups/monday.tar

that last one seems to cover exactly what you are trying to do.

faster:
it's as fast as your network connection

secure:
it's as secure as the FTP protocol (which isn't very). You still have to hard code your ftp credentials in your scripts.
 
  


Reply

Tags
bash, ftp



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
Using BASH script to transfer a file via (s)ftp senther Linux - Newbie 2 07-19-2005 04:47 PM
Pftp Mew timerx Linux - Newbie 0 12-05-2004 11:52 AM
PFTP -Mew himsa Linux - Newbie 6 04-07-2004 06:23 AM
PFTP-Mew Sebboh Linux - Software 0 03-22-2004 10:53 AM
pftp - can't compile owl123 Linux - Newbie 4 08-02-2003 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:21 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
Open Source Consulting | Domain Registration