Need of shell script to download data using ftp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need of shell script to download data using ftp
# 1  
Old 12-29-2012
Need of shell script to download data using ftp

Hi !

I am just wondering shell script to download data from ftp...

I have text file containing ftp address...looks like this

Code:
ftp://site...../filename.xyz
ftp://site...../filename.xyz
ftp://site...../filename.xyz
ftp://site...../filename.xyz

script has to read ftp address and then it has to download data using ftp...after downloading all data files, it should move all data to some directory, which will be having data files of last month, so basically it has to replace old files with new downloaded file..
# 2  
Old 12-29-2012
Look at wget

Code:
wget --user=vivek --password='myPassword' ftp://site...../filename.xyz

# 3  
Old 12-29-2012
An example shell script to ftp with...

You can modify this script to take parameters and download instead of upload...

Code:
#!/bin/sh
#THIS SCRIPT CONNECTS TO THE FTP SERVER
PASSWD='xxx'
USER='xxx'
full_file="$1"

cp $full_file . 1> /dev/null 2> /dev/null
ftp -niv ftp.xxx.com<<EOF 1> /dev/null 2> /dev/null
user $USER $PASSWD
binary
passive
cd pub
cd docs
put $1
bye
EOF




Quote:
Originally Posted by nex_asp
Hi !

I am just wondering shell script to download data from ftp...

I have text file containing ftp address...looks like this

Code:
ftp://site...../filename.xyz
ftp://site...../filename.xyz
ftp://site...../filename.xyz
ftp://site...../filename.xyz

script has to read ftp address and then it has to download data using ftp...after downloading all data files, it should move all data to some directory, which will be having data files of last month, so basically it has to replace old files with new downloaded file..
# 4  
Old 12-29-2012
Hi , I am very new to this site and as a shell script programmer also i am very novice . can you please tell me how its working .

Thanks in advance.


Quote:
Originally Posted by MattyV
You can modify this script to take parameters and download instead of upload...

Code:
#!/bin/sh
#THIS SCRIPT CONNECTS TO THE FTP SERVER
PASSWD='xxx'
USER='xxx'
full_file="$1"

cp $full_file . 1> /dev/null 2> /dev/null
ftp -niv ftp.xxx.com<<EOF 1> /dev/null 2> /dev/null
user $USER $PASSWD
binary
passive
cd pub
cd docs
put $1
bye
EOF

# 5  
Old 12-30-2012
If your download data is in url format, then wget is easier, no need to parse host, path and file.

Something like:
Code:
# download.txt like
# ftp://somehost/somepath/somefile

mkdir Old 2>/dev/null  # for previous version

while read url
do
     # make filename for url , replace chars / => _
     urlfile=${url//\//_}
     echo "Download $url to file $urlfile"
     cp -f "$urlfile" Old  2>/dev/null    # save old file
     rm -f "$urlfile"  2>/dev/null   # remove previous
     wget -q -O "$urlfile" --user xxxx --password yyyyyy "$url"
     # or anonymous site
     # wget -q -O "$urlfile" "$url"
done < download.txt # input file, include urls

# 6  
Old 12-30-2012
Hi kshji... I tried your script not working....please see the attachment...


after downloading all the files I want to replace with last time downloaded files in my directory

/home/nex/ftp_monthly
# 7  
Old 12-30-2012
Did you change my solution ? You need.
  • anonymous wget using
  • input file include empty lines - remove or handle those lines in script
  • use bash or ksh93 shell
  • before run the script, cd /home/nex/ftp_monthly
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Bash script for FTP download -Mysql

Hi guys, I recently managed to write up my working script, but now I have a problem. If the file isn't there in the remote server, my actual script jumps it and all ok, but I need something like this: Search file -> if there, then download -> if not, download next file in the list. Any... (7 Replies)
Discussion started by: virtus96
7 Replies

2. Shell Programming and Scripting

Download latest file via ftp server unix through shell script

Hello this is my first post in this forum , I dont want to be unhappy.. I am writing one script but facing difficulty to find the latest file with some new pattern My requirement is 1. The file is coming like "ABCD-23220140303" at FTP server once in a week. 2. script will run on daily... (3 Replies)
Discussion started by: ajju
3 Replies

3. Shell Programming and Scripting

FTP download using perl script

Need assistance I have a script which i can download the files from ftp server using perl . But i want to download multiple files at a time #!/usr/bin/perl -w use Net::FTP; $ftp = Net::FTP->new("ftp.ncdc.noaa.gov"); $ftp->login('username', 'password'); $ftp->cwd("<dir>");... (9 Replies)
Discussion started by: ajayram_arya
9 Replies

4. Shell Programming and Scripting

Download files every one second using ftp script

Our main Server "Srv1" is used to generate text files based on specified criteria and it is also connected to two clients (pc1 and pc2) which are responsible for getting the files from Srv1 as it follows: 1. pc1 ( which represents my UNIX machine ) uses shell script to copy the files from Srv1 2.... (3 Replies)
Discussion started by: arm
3 Replies

5. Shell Programming and Scripting

lftp script to connect to external sftp site and download to internal ftp and then send email

Hi there, I'm new to shell scripting and need some help if possible? I need to create a shell script (.sh) to run as a cron job on an ubuntu linux server to connect to an external sftp sites directory using credentials (which I have) and then download to our internal ftp server and then copy... (3 Replies)
Discussion started by: ghath
3 Replies

6. Shell Programming and Scripting

ftp script doesn't download jpg properly

ftp script doesn't download jpg properly The downloaded files have color splotches Here is the script: ftp -n me@institute.edu <<END_SCRIPT quote user name quote pass password prompt mget *.jpg quit END_SCRIPT exit 0 cd ../ (2 Replies)
Discussion started by: walforum
2 Replies

7. Shell Programming and Scripting

Help on FTP download using UNIX script

Hi guys, I'm new on this forum and on UNIX. Can somebody help in writing a script to download a file from an FTP server and validating if there is a file to download. If there is a file, I would send it to a mail recipient and if not I would generate an error log. Thanks in advance!:D (1 Reply)
Discussion started by: rjay_45
1 Replies

8. Shell Programming and Scripting

Download data from ftp.

Dear all, I am beginner to shell scripting. I have to download more than 1k files from ftp site. link is below ftp://ftp.ncbi.nih.gov/genomes/Bacteria/ Earlier i was using wget url, for download but the problem is some times folder names get changed, i don't know how to move in directories... (4 Replies)
Discussion started by: admax
4 Replies

9. Linux

shell script to download files from a site?

Hey everyone, my wife has purchased a bundle package of a bunch of images from a site, and now has to download each one of them manually. There are about 500 downloads, and it's quite a hassle to browse to each page and download them all individually. I would like to write a shell script to... (2 Replies)
Discussion started by: paqman
2 Replies

10. Shell Programming and Scripting

script for download files from ftp site

I'm new to scripting. I'm trying to write a script to download files from ftp site, the following is the script and the message i get after running the script. no files were downloaded :( Thanks advance! script: #!/usr/bin/ksh DAY=`date --date="-1 days" +%y%m%d` ftp -v -n "ftp.address" <<... (5 Replies)
Discussion started by: tiff-matt
5 Replies
Login or Register to Ask a Question