I installed FileZilla on my Win7 laptop to test this out for you. I ran the script from a Ubuntu VM. Note that I had to change some of the variables to make it work in my environment, so just change them back to what you had originally.

moritz was of course right about the FTP root directory. When you configure a user on your FTP server and set their 'shared directory' to "C:/Users/Win7/Desktop/intenship doc2/", you are automatically dropped into that directory when you log into the system via FTP. When I define the variable $directory in my code below, I specify I want to be in the root directory, which on the FTP server is the shared directory itself. I can not go up in the directory tree. If you print out $ftp->pwd() after you've logged in, you won't see the entire C:/Users... path at all.

In FileZilla I set up, I configured the 'stevieb' user with a 'shared directory' of C:/Users/steve/Desktop, and placed a file called 'blah.txt' there. Note in my code how I specify that I want to work in that directory. I've also fixed the code so that it is strict compliant (you should get in the habit of using 'use strict;' and 'use warnings;'

#!/usr/bin/perl use DBI; use Net::FTP; use File::Basename; use warnings; use strict; #connection paraneters to localhost my $IP='192.168.1.2'; my $users='stevieb'; my $password='blah'; my $directory="/"; #Connection to netboss my $ftp = Net::FTP->new($IP, Debug => 0, Passive => 0) or die "cannot +connect"; $ftp->login($users,$password); $ftp->cwd($directory); #list files my @fichier = $ftp->ls($directory); for my $entry (@fichier) { my $filename = basename( $entry ); if( $filename =~ "blah.txt" ){ # you'll need to uncomment the next line, and comment out # the one below it to return to your desired behaviour #$ftp->get($filename,"C:/users/Desk/personal".$filename); $ftp->get( $filename ); } } $ftp->quit;

In reply to Re: script for accessing ftp servers by stevieb
in thread script for accessing ftp servers by terrytedzi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.