Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

FTP Unix -> NT

by Anonymous Monk
on Nov 14, 2002 at 16:32 UTC ( [id://212901]=perlquestion: print w/replies, xml ) Need Help??

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

Ok I have an interesting problem, I need to FTP files from a UNIX machine to a Windows machine. I want to transfer log files so want this to happen automatically every night. How can I do this? I've looked at Net:FTP.pm but I can't get it to work... Any advice or help would be greatly appreciated.

Many thanks,
Tom

Replies are listed 'Best First'.
Re: FTP Unix -> NT
by Three (Pilgrim) on Nov 14, 2002 at 16:53 UTC
    Here is how I wrote a unix to nt fpt program
    Hope it helps
    use Net::FTP; #Connect to server $ftp = Net::FTP->new("1.1.1.1"); #Check for connection if ( $ftp->login("anonymous","anonymous") != 1 ) { return 0; } #Change to the directory if ( $ftp->cwd("dir") != 1 ) { return 0; } #Put file $status = $ftp->put($infile, $outfile); #Log off $ftp->quit;

      Thanks for the help guys, actually that bit of code above works! ;-) so I guess i'm sorted now!

      Thanks again!

Re: FTP Unix -> NT
by Mr. Muskrat (Canon) on Nov 14, 2002 at 16:39 UTC

    Show us the code!

    We'd love to help you but without knowing what you've tried, we are not going to be much use to you.

    P.S. Why not sign up for an account while you are at it? You just may find yourself in need of assistance again and having an account makes getting answers easier.

      hi again,
      actually I do already have a login, just too lazy to login! :-)

      OK, the code I have is as follows, but it's just a simple test thing to try and get FTP.pm to work.

      #!/usr/bin/perl -w

      use Net::FTP;

      my $hostname='216.74.109.245';
      my $user='username';
      my $password='password';
      my $ftp=Net::FTP -> new($hostname) or die ("Connect failed");
      $ftp->login($username,$password) or die ("Cant log in");
      $ftp->binary;
      $ftp->cwd("/public_ftp") or die ("Cant change directory");
      $ftp->put("mystuff.txt") or die ("Cant put stuff on server");
      $ftp->quit

      It produces:
      Name "main::username" used only once: possible typo at ./ftp-logs.pl line 9.
      Cant log in at ./ftp-logs.pl line 9.

      However, I am pretty sure my login information is correct and I can connect via the unix FTP prompt fine.

      I'm also slightly concerned whether it's working ok because I had to manually create the Net::Config.pm file by copying it from cpan because it didn't exist in my system originally, but was required by the Net::FTP.pm module.

      Hmm i'm confused...
      thanks,
      Tom

        You are storing the username in $user but you are attempting to login using $username.

        -- vek --
        Yes, it will not work, read this:
        Name "main::username" used only once: possible typo at ./ftp-logs.pl line 9. his "

        use "use strict;" ALL the time. You mis-spelled, one place it is $username, and then it is $user.

        If the server, username and password aren't changed very often, you might just try simplifying it down to:

        #!/usr/bin/perl -w use strict; use Net::FTP; my $ftp = Net::FTP->new('216.74.109.245') or die "Server not found"; $ftp->login('username','password') or die $ftp->message(); #$ftp->binary(); $ftp->ascii(); # you probably want to send it as ASCII instead of bin +ary if it is a text file $ftp->cwd("/public_ftp") or die $ftp->message(); $ftp->get("mystuff.txt") or die $ftp->message(); $ftp->quit;

        You will see that I removed the variables that you were using only once. I also let the Net::FTP session provide it's own error messages.

Re: FTP Unix -> NT
by pg (Canon) on Nov 14, 2002 at 16:59 UTC
    I use Net::FTP, so I know it works. What exactly is your problem, 1)The FTP doesn't work?, or 2)your FTP piece was never triggered, due to for example scheduling problem etc?
    Can you show us your code, otherwise it would be difficult to comment.
Re: FTP Unix -> NT
by princepawn (Parson) on Nov 14, 2002 at 17:00 UTC
    shouldn't he use ascii mode so that line-endings are converted on the uploaded files?

    Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

Re: FTP Unix -> NT
by rbc (Curate) on Nov 14, 2002 at 18:38 UTC
    You could use a shell script for this ...
    #!/bin/sh HOST=123.123.123.123 USER=username PASS=password ftp -n <<EOT user $USER $PASS cd /public_ftp bin put mystuff.txt bye EOT

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found