nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

script for uploading files to a FTP server

This is a discussion on script for uploading files to a FTP server within the Shell scripting forums, part of the Development/Scripting category; Hi, Is there a way to open a connection to a FTP server and upload the files I want? Say ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 11-24-2005, 10:44 PM
Junior Member
User
 
Join Date: Feb 2005
Posts: 23
Rep Power: 0
marinm
Default script for uploading files to a FTP server

Hi,

Is there a way to open a connection to a FTP server and upload the files I want? Say I have some backups which I want to upload to a secure server. The backups are named something like backup.`date +%d.%m.%y`.tgz. I need to upload these daily files to FTP. I believe NET::FTP (or something like that - if this help is installed.

Thank you guys!

Love this site
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-25-2005, 12:33 AM
Junior Member
User
 
Join Date: Sep 2005
Posts: 25
Rep Power: 0
charvi
Default

Here is sample code:

Code:
#/bin/bash
FTPU="user" # ftp login name
FTPP="passwd" # ftp password
FTPS="ftp.server.com" # remote ftp server
FTPF="/home/backup/" # remote ftp server directory for $FTPU & $FTPP
LOCALD="backup.$(date +%d.%m.%y).tgz"
ncftpput -m -u $FTPU -p $FTPP $FTPS  $FTPF $LOCALD
Try out and let us know if it works or NOT
Reply With Quote
  #3 (permalink)  
Old 11-25-2005, 12:37 AM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

dam charvi you are too fast

May this http://bash.cyberciti.biz/ftp/ftptreeupload.bash.html help u, it is same stuff but u need ot make few mods
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #4 (permalink)  
Old 11-25-2005, 03:53 AM
Junior Member
User
 
Join Date: Feb 2005
Posts: 23
Rep Power: 0
marinm
Default

Hi!

Thanks for the prompt replies. I don't have ncftp. Do I need ncftp to be able to make this work? Can't this be done with the normal "ftp" program?

Thanks,
Marin Micoriciu
Reply With Quote
  #5 (permalink)  
Old 11-25-2005, 01:19 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default ftp shell automate login script

FTP client is bit outdated, ncftpput is a special program for Internet file transfer program for scripts, hence it is recommended. Anyways if you still wanna use ftp client then please follow following steps

1)First create ftp login file with user name and password
Code:
vi ~/.netrc
2) Put following text into it
Code:
default login FTPUSERNAME password FTPPASSWORD
3) Save the file and set permission on it
Code:
chmod 0600 ~/.netrc
4) Create a script as follows
Code:
#!/bin/bash
HOST='ftp.myhost.com'
FILE="backup.$(date +%d.%m.%y).tgz" 
ftp  -i $HOST <<END_SCRIPT
put $FILE
quit
END_SCRIPT
exit 0
Save script and execute it:
Code:
chmod +x ftpscript
./ftpscript
This only way to work with ftp script under Linux (as ftp client used by Debian is from Linux netKit project) all other scripts on ftp automation out on net are old and mostly will not work.
Reply With Quote
  #6 (permalink)  
Old 11-25-2005, 09:11 PM
Junior Member
User
 
Join Date: Feb 2005
Posts: 23
Rep Power: 0
marinm
Default

Quote:
Originally Posted by charvi
Here is sample code:

Code:
#/bin/bash
FTPU="user" # ftp login name
FTPP="passwd" # ftp password
FTPS="ftp.server.com" # remote ftp server
FTPF="/home/backup/" # remote ftp server directory for $FTPU & $FTPP
LOCALD="backup.$(date +%d.%m.%y).tgz"
ncftpput -m -u $FTPU -p $FTPP $FTPS  $FTPF $LOCALD
Try out and let us know if it works or NOT
I have installed ncftp and this script works like a charm!

Thank you charvi and rockdalinux!! You guys rule!

Regards,
Marin M.
Reply With Quote
  #7 (permalink)  
Old 11-30-2005, 09:52 PM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

Heh these guys always rulez
Reply With Quote
  #8 (permalink)  
Old 01-02-2006, 08:35 PM
Junior Member
User
 
Join Date: Feb 2005
Posts: 23
Rep Power: 0
marinm
Default

Quote:
Originally Posted by tom
Heh these guys always rulez
That's true
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
script for FTP'ing 8 differnt server for pulling the files vishal_titre Shell scripting 0 08-17-2007 07:09 PM
How to Prevent Uploading Perl Scripts in /tmp Directory bipinkdas Web servers 1 06-25-2007 09:57 PM
Script to extract some part of files: satish1482 Shell scripting 0 03-13-2007 06:30 PM
Shell script for automatic conversion of files in tar files kasimani Shell scripting 2 02-08-2007 04:45 PM
Script to remove executable files sweta Shell scripting 4 03-12-2005 02:21 PM


All times are GMT +5.5. The time now is 06:32 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36