Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Downloading files from ftp server

Status
Not open for further replies.

chandershivdasani

Programmer
Jun 3, 2009
1
US
I have a file say at the following location on an ftp server
"/edgar/full-index/1993/QTR2".

I am downloading the file and storing it on my local machine. I want it to store it with the same folder hierarchy. For example, suppose my current folder is C: so after my code runs, the file should be at the following location,
"C://edgar/full-index/1993/QTR2".

The following is the code that i have written, but it is giving the following error:
Cannot open Local file C:/edgar/full-index/1993/QTR1: No such file or directory
at get-master.pl line 42

use Net::FTP;
use strict;

my $start_year = 1993;
my $start_qtr = 1;

$ftp = Net::FTP->new(HOST) or die;
$ftp->login('anonymous')
$ftp->cwd("/edgar/full-index/$start_year/QTR$start_qtr") or die "$@";

$ftp->get('master.idx',"C:/edgar/full-index/$start_year/QTR$start_qtr") or die




 
You have to make the directory yourself first; the FTP module won't do that for you.

Also you may need to changes the slashes to the Windows/DOS backslash format, unless the FTP module copes with that automatically. Remember you will probably need to escape them to remove their special meaning, e.g. "C:\\edgar\\full-index\\...".

Annihilannic.
 
Annihilannic:

In my experience, Perl on Windows has never required backslashes in path names. I've always used them with forward slashes:

Code:
C:\Users\kirsle\Console2>perl
open (TEST, ">C:/Users/Kirsle/Desktop/my-file.txt");
print TEST "hello world!";
close (TEST);
__END__

C:\Users\kirsle\Console2>type ..\Desktop\my-file.txt
hello world!

Windows allows forward slashes as well as backslashes on the command line; DOS might be the only Windows-like system that requires only \'s to be used, but, is there even a Perl implementation for DOS? (I'm curious, I'll go look into that)

But for most practical purposes, using regular forward slashes in Windows is just fine (there may be problems with Windows 3.1 being that it's practically a DOS app and not an operating system).

Plus forward /'s make the code portable to other operating systems (provided you don't use "C:/" and stick to relative path names ;-) ).

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top