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

I am in desperate need of a solution! I am using NET::FTPf from an NT Box, to "put" small .txt files in a dump area on an NT box, (using Passive Mode and setting it to binary) I can make the connection, login, connect to the right directory, but when I actually transfer, ONLY the file name is transferred/(or created), not the actual contents... Why oh why don't the contents transfer...????

Replies are listed 'Best First'.
Re: NET::FTP Problem
by derby (Abbot) on Aug 19, 2002 at 16:16 UTC
    Some code would be nice.

    -derby

      Sorry, I am new at this:

      #!/D:/perl/bin/-w # a module making life easier use Net::FTP; use strict; use warnings; require Net::FTP::A; my $file = "ftptest.txt"; my $host = "somehost.com"; my $login = "me"; my $passwd = "pass"; my $ftp = Net::FTP->new("somehost.com", Debug => 1); if ($ftp->login("me","pass")) { $ftp->cwd('OMS'); #$ftp->pasv( $ftp ); $ftp->I(); $ftp->put( $file ); } else { print " Sending file to FTP Server ... Failed!\n"; } print " Sending file to FTP Server ... "; if ($ftp->put($file)) { print "Complete!\n"; } else { print "Failed!\n"; $ftp->quit; } $ftp->quit;</P>

      Edited: ~Mon Aug 19 18:16:20 2002 (GMT) by footpad: Added <CODE> and other HTML formatting tags, per Consideration.

        Check out the Beginners guide to Net::FTP. You should be checking the return values as already mentioned, and displaying the correct error messages (well, maybe you don't need that in debug mode, but derby has them wrong further down in this thread). And I really don't think you need the explicit require of Net::FTP::A.
Re: NET::FTP Problem
by derby (Abbot) on Aug 19, 2002 at 18:50 UTC
    Also, check the return values of your ftp commands. There may be a failure and FTP will not clean up after itself.

    #!/usr/bin/perl -wd use strict; use warnings; use Net::FTP; my $file = "ftp.pl"; my $host = "some_host"; my $user = "a_user"; my $pass = "the_pass"; my $ftp = Net::FTP->new( $host ) or die "Could not open $host\n"; $ftp->login( $user, $pass ) or die "Could not login\n"; $ftp->put( $file ) or die "Could not put $file\n"; $ftp->quit();

    -derby

    update: Updated the error messages (thanks runrig and see Beginners guide to Net::FTP).

Re: NET::FTP Problem
by RMGir (Prior) on Aug 19, 2002 at 18:16 UTC
    Here's your code, reformatted with <code> tags...
    #!/D:/perl/bin/-w # a module making life easier use Net::FTP; use strict; use warnings; require Net::FTP::A; my $file = "ftptest.txt"; my $host = "somehost.com"; my $login = "me"; my $passwd = "pass"; my $ftp = Net::FTP->new("somehost.com", Debug => 1); if ($ftp->login("me","pass")) { $ftp->cwd('OMS'); #$ftp->pasv( $ftp ); $ftp->I(); $ftp->put( $file ); } else { print " Sending file to FTP Server ... Failed!\n"; } print " Sending file to FTP Server ... "; if ($ftp->put($file)) { print "Complete!\n"; } else { print "Failed!\n"; $ftp->quit; } $ftp->quit;
    First, a few questions: Why is the first $ftp->put($file) there?

    Why isn't your print in the first else clause a die?

    Why 2 calls to $ftp->quit()?

    Why the "require" of Net::FTP::A? You don't need that, at least, not for this snippet.

    Apart from the questions, did you notice that your call to pasv is commeted out? That could cause you some problems, maybe even the exact problem you mention.
    --
    Mike

Re: NET::FTP Problem
by jlarson (Initiate) on Aug 19, 2002 at 18:51 UTC
    I would do $ftp->put_unique($file); #Just so you do not overwrite a file if it exists. do you need to send binary or ascii? use $ftp->binary(); or $ftp->ascii();