Unable to Download File from FTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to Download File from FTP
# 1  
Old 08-02-2017
Unable to Download File from FTP

Hi,

I am trying to download files from FTP using below FTP code.

Code:
 x=$(TZ=CST date +%Y%m%d)
host='xxx.xx.xxx.xxx'
user='userX'
pass='Password'
echo "Connecting to FTP Host -- $host....."
echo $x
a=$(ftp -v -n -i << !
open $host
user  "$user" $pass
cd /rose/yellow/
mget Daily_rose_$x_report.csv
!)

Ideally file Daily_rose_20170802_report.csv should get downloaded from FTP to my local drive.

I am getting the below error

Code:
 The system cannot find the file specified.
Cannot find list of remote files.

Request in support to debug the above code.

Regards,
Ram
# 2  
Old 08-02-2017
Mayhap stating the obvious: Does /rose/yellow/Daily_rose_20170802_report.csv exist on the target host, and does the remote user have access permission?
# 3  
Old 08-02-2017
First, don't put username and password in a script. Use instead a file called .netrc
Code:
$ cat ~/.netrc
machine xxx.xx.xxx.xxx login userX password xxxxx

Second, the mget command is for multiple files. Try using get instead.

Are you sure the file exists? What happens when you use the ls command to ftp instead?

Also, consider installing and using lftp instead. Not only does it grok multiple protocols including FTP, SFTP and FTPS; it comes with a shell wrapper lftpget for fetching single or multiple files.

Andrew
# 4  
Old 08-02-2017
Hi,

Yes the file does exist, the problem is when file name ends with date
Code:
Daily_rose_20170802.csv

my code is working perfectly, but when file name is
Code:
Daily_rose_20170802_report.csv

after date any other string in file name, then the code is giving error. Moreover I am using CYGWIN to perform the task.

Regards,
Ram
# 5  
Old 08-02-2017
Enclose the x variable expansion in braces, like ..._${x}_....
These 2 Users Gave Thanks to RudiC For This Post:
# 6  
Old 08-02-2017
To back up what my learned friend RudiC says, the reason is that the underscore is not seen as delimiting the end of the variable. It is an allowable character in the variable name, so you will end up evaluating $x_report which is probably not set, so you will always try to get Daily_rose_.csv If the file had used hyphens instead of underscores then you would have got away with it, but only by luck.

Some shells also have limitations on arguments, e.g. $1. As a minor war-story, I had to debug a script once which accepted ten arguments and referred to $10 It took me ages to work out was that $10 was actually the value of $1 followed by a zero and this was required by some odd processing in the script. When it needed to use the value of $10, the author had done a shift and referred to $9 instead confusing everything else as the script looped.

The escape from this madness was to use ${10} and remove the shift, so it is good practice to wrap variable names in {} anyway.



Kind regards,
Robin
This User Gave Thanks to rbatte1 For This Post:
# 7  
Old 08-02-2017
Hi Friends,

The solution provided had worked perfectly, and thanks for your detailed input.

Regards,
Ram
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read latest file name with a date and time and then download from FTP

Hi All, Please help. I have requirement to read the file / folder based on the latest date and download the file and folder. There will be files and folders in the location like 20140630-144422 20140630-144422.csv 20140707-182653 20140707-182653.csv 20140710-183153... (7 Replies)
Discussion started by: Praveen Pandit
7 Replies

2. Shell Programming and Scripting

Wanted to download the yesterday's file through FTP

Hello, Wanted to download the yesturday's or current date-1 file through shell script Mode: FTP OS: AIX if today is 13th May then file would be available as below. File Pattern:201401148682_daily_2014-05-12.txt.zip Help.. (4 Replies)
Discussion started by: Riverstone
4 Replies

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

4. Shell Programming and Scripting

FTP File download

Hi, I have few files at FTP location and have written a script to download the same from ftp based on the sysdate - 1, however with the below code I am unable to download the files from FTP. x=`TZ=CST+24 date +%Y%m%d` mget Daily_BIH_$x_NEW.tar.gz can anyone please help me in... (10 Replies)
Discussion started by: rramkrishnas
10 Replies

5. UNIX for Advanced & Expert Users

Want to download a latest file with current date from FTP location

Dear Friends, I need help to write a shell / perl script to download the files from FTP location, having different file names (date inside the file name). Example: Mar 5 09:24 cfx_03052013_return_file.txt Mar 6 02:13 cfx_03062013_return_file.txt Mar 7 06:40... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

6. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

7. Shell Programming and Scripting

Question about how to ftp download the latest file from a directory

Dear all, Hope you are doing well. I am in trouble to write a shell for ftp downloading the latest file from remote server. Situation: There is a directory named 'weekly' which contains .csv files with the following pattern: RES_EN_100417-080003.csv.Z. The new file is generated... (3 Replies)
Discussion started by: kel1014
3 Replies

8. Shell Programming and Scripting

How to download X bytes from a file using ftp or http?

Hi, I have a simple ftp shell script which can download the entire file, however I want to know if there is anyway that I can download only the partial content, say X bytes from a file. If so, how I can do it using ftp and http.. Here is my sample script #!/bin/sh HOST='xyz.com' ... (5 Replies)
Discussion started by: learn more
5 Replies

9. Shell Programming and Scripting

download specified file from ftp server

Hi all, I'm having problems downloading files from ftp server. I have to download only those files that name starts with YYYYMMDD.But file comes like the format "20080624221035.TXT".Also how i can get list of all file names with in specified folder. Here i paste my code ftp -vn... (1 Reply)
Discussion started by: vaskarbasak
1 Replies

10. Solaris

Urgent...FTP unable finish download file, hang half way

Hi all, I have 1 problem in my solaris 8 server. The problem is in every nite that will run a cron job to download file from external ftb server. This crob job starter running find, but after running for 4 minute, that ftp services is hang that, until we need kill this process. My question... (3 Replies)
Discussion started by: foongkt5220
3 Replies
Login or Register to Ask a Question