Help needed with automated FTP script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed with automated FTP script
# 1  
Old 07-09-2008
Question Help needed with automated FTP script

Hi,

Ok, i'm trying to automate sending a DB backup from a linux box to a remote Windows PC via FTP. I can connect, send the file and create a folder, however I require that the backups be differentiated by date. Here is what my script looks like:

Code:
open *.*.*.*
user username password
lcd /location/of/DB/backup
mkdir %Y/%m/%d
cd %Y/%m/%d
put test.txt
bye
quit

This does not work, its just creates a folder named "%Y" with a folder inside it called "%m" with a "%d" folder inside that.

How would I go about creating folders with the date structure above on a the remote windows machine? All advice and help appreciated.
# 2  
Old 07-09-2008
Code:
.......
test ! -d `date "+%Y/%m/%d"` && mkdir -p `date "+%Y/%m/%d"`
cd `date "+%Y/%m/%d"`
.......

# 3  
Old 07-09-2008
Try something like this:

Code:
#!/bin/sh

Y=`date "+%Y"`
m=`date "+%m"`
d=`date "+%d"`

cd /location/of/DB/backup

ftp -i -n <<EOF
open "hostname"
user "user" "passwd"
mkdir "$Y"/"$m"/"$d"
cd "$Y"/"$m"/"$d"
put test.txt
quit
EOF

Regards

Last edited by Franklin52; 07-09-2008 at 01:47 PM..
# 4  
Old 07-09-2008
How about this.
Code:
file_date=$(date +%m%d%Y)
ftp -in 0.0.0.0 <<E-O-F
user username password
type ascii
mkdir $file_date
cd $file_date
put somefile
quit
E-O-F

# 5  
Old 07-10-2008
Quote:
Originally Posted by Franklin52
Try something like this:

Code:
#!/bin/sh

Y=`date "+%Y"`
m=`date "+%m"`
d=`date "+%d"`

cd /location/of/DB/backup

ftp -i -n <<EOF
open "hostname"
user "user" "passwd"
mkdir "$Y"/"$m"/"$d"
cd "$Y"/"$m"/"$d"
put test.txt
quit
EOF

Regards
Kudos! That works perfectly Smilie Much appreciated, you've made this Irishman very happy, I have one less job today, lol Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting local server file from automated FTP script

Hi, I want to delete a file on the local server, while connected to remote server through FTP. I am using the below code for this $FTP_CMD -v -n $HOST <<*! >> $LOGFILE 2>&1 user $USER $PASSWORD cd $DIR ... (11 Replies)
Discussion started by: jhilmil
11 Replies

2. Shell Programming and Scripting

shell script help needed to manage FTP automation

Hi, I am very new in shell scripting. Have managed to prepare a script which will work to download data to local directory. But facing below problem. :wall: Please help me out. Thanks in advance. Problem: 1. I am unable to use delete command to delete data in the ftp location (I have... (2 Replies)
Discussion started by: ImranBD
2 Replies

3. Shell Programming and Scripting

Automated FTP without plaintext user/password in script

hi , i am a still beginner in unix and specially in ftp i've written this script but my admin asked me that he don't want to see in my ftp neither user neither password , so i've created .netrc file where in it i've put machine name , user and pass but still included in my script , so if someone... (19 Replies)
Discussion started by: semaan
19 Replies

4. Shell Programming and Scripting

Automated script to look for files in FTP Server location.

suppose one file comes in one sever location on MOnday.we have to write a script to automatically get that files and put it in different server location. ---------- Post updated at 10:28 AM ---------- Previous update was at 10:27 AM ---------- Please help me on this (2 Replies)
Discussion started by: sonam273
2 Replies

5. Shell Programming and Scripting

Automated FTP

Hello,I just know the basics of scripting & I need a script to automate ftp since I use it quite often. I use ftp to transfer different kind of files and everytime the source & the destination directories are different for transferring files, so can anyone help me out on this urgently.. (2 Replies)
Discussion started by: mohit_02mar
2 Replies

6. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

7. UNIX for Advanced & Expert Users

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies

8. Programming

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies

9. Shell Programming and Scripting

automated ftp script from unix -date range of files

Hi , I need some help to finish my ftp script and i need to find the last one weeks of fles updated in the sepecific directory and see those end with Z and ftp them to my backup server. Any help is appreciated. Thanks, Ravi :) (1 Reply)
Discussion started by: koduri0475
1 Replies

10. UNIX for Dummies Questions & Answers

FTP automated?

If I wanted a machine to put a specific file onto another OS far across the internet via FTP - and I wanted to do it automatically not user intervented, how would I do that? Use the PUT command? The file name and position never changes, it gets overwritten and the system on the other end... (6 Replies)
Discussion started by: n9ninchd
6 Replies
Login or Register to Ask a Question