Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

need to ftp file

by dxd (Initiate)
on Jan 19, 2005 at 17:39 UTC ( [id://423447]=perlquestion: print w/replies, xml ) Need Help??

dxd has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script running on a linux server and need to connect to a windows nt server and down load a file. The problem is that I only know the start of the file name and the ext . I tried to rename the file on the windows server using a wildcard in the perl script but it did not work. Is there a way to get perl rename the file or down load the file to the linux box and then rename it???

Replies are listed 'Best First'.
Re: need to ftp file
by Limbic~Region (Chancellor) on Jan 19, 2005 at 17:49 UTC
    dxd,
    Presumably, you are using Net::FTP. There is a rename method but it requires knowing the original filename first. I do not know if file globbing works in Net::FTP, but with regular FTP you can use mget when you aren't exactly sure of the name. In lieu of that, you can always use the ls method to get a list of files and then get matching files that meet your pattern. You can then rename/get each one individually.

    Cheers - L~R

Re: need to ftp file
by MZSanford (Curate) on Jan 19, 2005 at 21:08 UTC
    If you are using Net::FTP as has been suggested you need to use the dir() method to get a remote list, and then use foreach to go through that looking for the file you want (which I assume matches some pattern). Can you confirm you are using Net::FTP ?

    from the frivolous to the serious
Re: need to ftp file
by Tanktalus (Canon) on Jan 19, 2005 at 17:48 UTC

    Could you give us a bit more information - including, perhaps, the code you've got so far? Thanks.

    (The problem with TMTOWTDI is that we don't know which way you're doing it ;->)

      Hi I am running the perl script on linux and connecting to the windows server and then down loading the file from windows. The script works fine when I know the full file name but, the name is now changing daily (only the the first 3 chars and the ext are the same now) from day to day. I was trying to do a rename on the windows server thru my perl script but I can not get that to work at all.
Re: need to ftp file
by sweetblood (Prior) on Jan 19, 2005 at 18:36 UTC
    I don't believe you can glob a file using Net::FTP, however you can probably use Perl's glob to get the filename and pass it during your ftp put.
    #!/usr/bin/perl -w use strict; use Net::FTP; my $user = 'XXXX'; my $password = 'XXXXX'; my $ftp = Net::FTP->new('your_ftp_box'); $ftp->login($user, $password); my $file = glob 'whatever*you*need'; $ftp->put($file, 'whatever_name_you_want'); $ftp->quit;
    You should also read perldoc Net::FTP to be certain you know what's going on here. Also this example does not do any error checking you can figure that out by reading perldoc Net::FTP, but this will give you an idea.

    Good luck

    Sweetblood

      I don't see glob could help. glob will work on his local filesystem and anything that ended up in $file would have no relavance to the non-local windows box.
Re: need to ftp file
by gaal (Parson) on Jan 19, 2005 at 23:31 UTC
    Can you share the directory the file is on and access it with Samba from the linux box? This will allow your code to be simpler; of course, it adds work to the admin and may not be an option at all.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://423447]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-23 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found