Curl ftp ssl download files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Curl ftp ssl download files
# 1  
Old 07-30-2013
Curl ftp ssl download files

Hello all,
I have been struggling with this issue on and off for a couple of weeks now and I just got it all working, so I wanted to share my findings in case some other poor soul needs to know how. First some background on what I'm doing. I am uploading files to different directories based on the filename to a ftp w/SSL site, then getting files from different directories from the same ftp w/SSL site without knowing the file names. Sending was fairly easy, but the getting was a real pain since there is no mget equivalent in curl. So I had to find a way to get the file names before getting the files themselves. So here's how I did it.

In the root of the directory that I am running in I have a file named file_strings_get which contains the directories I need to check:
-------------------------------
Code:
outbound/DIR01
outbound/DIR02

-------------------------------
There is also a file named ftp_env.conf in the same location that contains all the important environment variables that I need:
-------------------------------
Code:
#ftp_env.conf
set clientname="<Client Full Name>"
set clientnum="<Customer Number>"
set fromdirname="/path/to/where/files/are/downloaded/to"
set ftpaddr="username:password@ftp.server.com"
set workingdir="/path/to/scripts"
set admin_mail='ftpadmin@yourdomain.com'

--------------------------------
Now my shell script which does all the work which I have named getnnotify.csh
--------------------------------
Code:
#!/bin/csh
#########################################
#		getnnotify		#
#	A script to pick-up files from	#
#	ftp using SSL	#
#########################################
#########################################
# Get and Set Varaibles from file       #

source /path/to/scripts/ftp_env.conf

#########################################
#       Create an empty log file        #

cat /dev/null >! /tmp/$clientnum.log.$$

#########################################
# Change to the clients working directory #

cd $fromdirname

#########################################
# FTP to client and pick-up files 	#

foreach i ( `cat $workingdir/file_strings_get` )
        set directory = `echo $i | awk -F'|' '{print $1}'`
        foreach file (`/usr/bin/curl -l --ftp-ssl-reqd ftp://$ftpaddr/$directory/`)
                (/usr/bin/curl -v --ftp-ssl-reqd -O ftp://$ftpaddr/$directory/$file) >>& /tmp/$clientnum.log.$$
				if ($status != 0) then
					goto error
				endif
		end
end

#########################################
# Email the log
/usr/ucb/Mail -s "$clientname File Transfer Log for `date +%D`" $admin_mail < /tmp/$clientnum.log.$$

done:

#########################################
# Delete the log
/bin/rm -f /tmp/$clientnum.log.$$

exit 0

error:

/usr/ucb/Mail -s "$clientname Inbound File Transfer Failed for `date +%D`" $admin_mail < /tmp/$clientnum.log.$$

#########################################
# Delete the log

/bin/rm -f /tmp/$clientnum.log.$$

exit 1

---------------------------------------------------------------

That's it, I hope this script or at least the logic will help someone else out there who might be struggling with a similar issue.

Last edited by Don Cragun; 07-30-2013 at 05:34 PM.. Reason: CODE tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Curl command to download multiple files with a file prefix

I am using the below curl command to download a single file from client server and it is working as expected curl --ftp-ssl -k -u ${USER}:${PASSWD} ftp://${HOST}:${PORT}/path/to/${FILE} --output ${DEST}/${FILE} let say the client has 3 files hellofile.101, hellofile.102, hellofile.103 and I... (3 Replies)
Discussion started by: r@v!7*7@
3 Replies

2. UNIX for Dummies Questions & Answers

How to download files matching pattern from FTP using CURL or WGET?

Hi, For an order I requested, the provider has uploaded a tar file in public FTP site which internally has tons of files (compressed) and I need to download files that follows particular pattern which would be few hundreds. Note: The order can't be requested for files that follows the... (7 Replies)
Discussion started by: Amalan
7 Replies

3. 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

4. UNIX for Advanced & Expert Users

Help with using curl to download files from https

Hi I'm trying to download an xml file from a https server using curl on a Linux machine with Ubuntu 10.4.2 I am able to connect to the remote server with my username and password but the output is only "Virtual user <username> logged in". I am expecting to download the xml file. My output... (4 Replies)
Discussion started by: henryN
4 Replies

5. Shell Programming and Scripting

curl script to download files from Secured HTTPS server?

curl -# -v -d "sendusername=myname&password=mypassword&wheretogo=download.php" -L -o test.zip http://www.ims-dm.com/cgi/securedownload.php?p=HIREFTPM\&prodtype=hire/test.zip * About to connect() to www.ims-dm.com port 80 * Trying 209.61.193.139... connected * Connected to www.ims-dm.com... (1 Reply)
Discussion started by: laknar
1 Replies

6. Shell Programming and Scripting

Shell Script for Upload/download files using cURL

hi please help me out here, i want to use curl command in shell script to test web pages, what i have is an opening page, when i click on a button on opening page, the next page comes up and then i have to upload a file n then click another button to submit and then comes the output page,... (2 Replies)
Discussion started by: Olivia
2 Replies

7. Shell Programming and Scripting

Download previous day files through FTP

Hi All, I have a scenario where I need to download the previous day modified files from other server to my server through FTP . Could any one please send me the shell script for the same. I used the following but I dont know how to proceed after this. ftp -n -i -v $IP <<ENDOFinPUT >>... (3 Replies)
Discussion started by: sarathchandrach
3 Replies

8. 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

9. Shell Programming and Scripting

help with curl using ssl to ftp file

Currently I am trying to download a file from a secure site that I do not control. I need to use a pem cert to get past their firewall. Currently I am trying to use curl to get the file and return it using the following information pemcert.txt containing the cert, username, password, domain,... (0 Replies)
Discussion started by: gandolf989
0 Replies

10. UNIX for Dummies Questions & Answers

cURL Active FTP Download

Hello, I know this is probably a very silly question for most but how to do I force curl to do active FTP downloads? Thank you Dallas (2 Replies)
Discussion started by: Dallasbr
2 Replies
Login or Register to Ask a Question