Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Net::FTP put failing silently?

by welchavw (Pilgrim)
on Aug 06, 2008 at 20:16 UTC ( [id://702728]=perlquestion: print w/replies, xml ) Need Help??

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

UPDATE:I am giving up on this - feel free to do that, too

Net::FTP client script is not working. See how the put command appears to work, but the directory listing comes back empty. I feel like I am missing something easy. The FTP server works via ftp commandline client. Thanks. Code snippet is...

my $remote_file = $ftp->put($name) || die $ftp->message; print "remote_file $remote_file\n" unless $log_level < 3; print "ftp dir listing...", $ftp->dir(), "\n" unless $log_leve +l < 3; print "ftp pwd...", $ftp->pwd(), "\n" unless $log_level < 3;
Output is...
putting /runtime/images/rear_imgs_to_be_sent/0031061000211897171830451 +00000000000000000.tif as 003106100021189717183045100000000000000000.t +if Net::FTP=GLOB(0x83c71e4)>>> ALLO 984060 Net::FTP=GLOB(0x83c71e4)<<< 200 ALLO command successful. Net::FTP=GLOB(0x83c71e4)>>> PORT 10,255,1,101,194,26 Net::FTP=GLOB(0x83c71e4)<<< 200 PORT command successful. Net::FTP=GLOB(0x83c71e4)>>> STOR 0031061000211897171830451000000000000 +00000.tif Net::FTP=GLOB(0x83c71e4)<<< 150 Opening BINARY mode data connection fo +r 003106100021189717183045100000000000000000.tif. ###################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +##################################################################### +############################################################## Net::FTP=GLOB(0x83c71e4)<<< 226 Transfer complete. remote_file 003106100021189717183045100000000000000000.tif Net::FTP=GLOB(0x83c71e4)>>> PORT 10,255,1,101,219,80 Net::FTP=GLOB(0x83c71e4)<<< 200 PORT command successful. Net::FTP=GLOB(0x83c71e4)>>> LIST Net::FTP=GLOB(0x83c71e4)<<< 150 Opening BINARY mode data connection fo +r /bin/ls. Net::FTP=GLOB(0x83c71e4)<<< 226 Transfer complete. ftp dir listing...

Replies are listed 'Best First'.
Re: Net::FTP put failing silently?
by Khen1950fx (Canon) on Aug 06, 2008 at 22:09 UTC
    Never "give up". Try this for your put Re: Net:FTP Not overwrite files. It uses Net::FTP::File.

    Update: I've been working on this example for a while now. The put cmd isn't allowed, so I used get. Added Filter::cpp

    #!/usr/bin/perl use strict; use warnings; use Net::FTP; use Filter::cpp; use constant HOST => 'ftp.perl.org'; use constant DIR => '/pub/CPAN'; use constant REMOTE_FILE => 'README'; my $ftp = Net::FTP->new(HOST, Debug => 1, Passive => 1) or die "Couldn +'t connect: $@\n"; $ftp->login('anonymous'); $ftp->cwd(DIR); $ftp->ascii(); $ftp->pwd(); #define DEBUG my $x = 'log_level'; my $log_level; #ifdef DEBUG $log_level = 1; #else $log_level = 3; #endif ($log_level <= 3) and print "$log_level <= 3: \$x is \"$x\"\n"; $ftp->get(REMOTE_FILE) unless $log_level == 3; print "Done\n" unless $log_level == 3; $ftp->quit;
Re: Net::FTP put failing silently?
by spivey49 (Monk) on Aug 06, 2008 at 20:41 UTC

    my $remote_file = $ftp->put($name) || die $ftp->message;

    I've been told || does not get processed the same as "or". Try changing the line to my $remote_file = $ftp->put($name) or die $ftp->message; . That might show that your FTP put isn't really failing silently.

    Are you sure you're in the correct directory for the listing as well?

      my $remote_file = $ftp->put($name) || die $ftp->message;
      means
      my $remote_file = ( $ftp->put($name) || die $ftp->message );

      my $remote_file = $ftp->put($name) or die $ftp->message;
      means
      ( my $remote_file = $ftp->put($name) ) or die $ftp->message;

      Both are fine here.

      Did not work, sorry. Besides, "Debug" output clearly indicates that Net::FTP thinks that the transfer succeeds.

        Sorry, missed that in the debug output. So if you use a command line client can you see the file as expected? I've seen puts work, but issues with ls commands behind firewalls before.

Re: Net::FTP put failing silently?
by starX (Chaplain) on Aug 06, 2008 at 20:38 UTC
    Have you checked other directories that you can write to as an FTP user? Is it possibly writing the file someplace else? If a unix system, try doing a find on the exact filename; if it is making it's way to the system in a different place, that would tell you where.
      Thanks, but other directories do not work. Also, using commandline FTP client with same user/pass works for exact same transfer. Truly, I feel lost.
Re: Net::FTP put failing silently? (problem src)
by ikegami (Patriarch) on Aug 06, 2008 at 21:09 UTC

    The *server* (or something masquerading as the server) says the transfer was successful ("226 Transfer complete."), so it's not a problem with Net::FTP.

      Yes, indeed. Any clue what could be involved? I have a transfer via Net::FTP that doesn't work while one over simple commandline ftp does work. This is to an NT FTP service. It would violate my expectation if security software were treating one FTP client differently, and I have tried passive on and off.

        If both passive and active modes are not working in the script, but the command line is, I would suspect a possible proxy. The client might be picking up your proxy settings, but the script isn't.

        If that were the case it typically wouldn't make much sense for the put to be working, but not the ls. The proxy should deny both. Of course different proxies have different levels of granularity in their policies. Maybe it's allowing ls, but not dir or applying a "guest" policy to allow puts, but not dir or ls.

        If both passive and active modes are not working in the script, but the command line is, I would suspect a possible proxy. The client might be picking up your proxy settings, but the script isn't.

Re: Net::FTP put failing silently?
by Perlbotics (Archbishop) on Aug 06, 2008 at 22:35 UTC
    Right, you shouldn't give up. I would give Wireshark (formerly Ethereal), snoop, tcpdump and the like a chance to see what is conveyed over the wire. Especially to see what is in the 226 bytes returned from the /bin/ls command. Good luck.
      Just to be clear.... There is no indication that 226 bytes are returned from the /bin/ls command. 226 is the server code for "Transfer Complete" (with no other indication of how many bytes were actually transferred).
        Oops. Have overseen that. Thanks. Nevertheless, having a look on wire will clarify if the problem is below or above the transport layer and on which side it can be solved best.
        Another random idea: The FTP commands are part of a print statement. I don't expect that this is a problem, but maybe ... it is worth to save the $ftp->dir() result in a variable and print it in a separate statement... just to exclude the (unlikely) possibility of some messed up I/O streams... ?
Re: Net::FTP put failing silently?
by eosbuddy (Scribe) on Aug 06, 2008 at 22:37 UTC
    Don't know if this might be relevant - try the ftp in passive mode. (also, please check the local port configuration for your ftp client - some servers use ports > 7000 for clients while your ftp client might be configured for ports < 5000 - if you're on a windows system, a system update could have changed it, or a local configuration of firewall could've changed it). When using command line ftp, it is in active mode and the < 5000 local port could be getting used. Just a thought :-)
Re: Net::FTP put failing silently? (empty listing perm)
by ikegami (Patriarch) on Aug 06, 2008 at 21:05 UTC
    Do you have permission ('r') to list the contents of the directory?
      Yes. Use of commandline with same user/pass works fine for all operations, including put, ls, del.
Re: Net::FTP put failing silently? (pwd)
by ikegami (Patriarch) on Aug 06, 2008 at 21:16 UTC
    I'd confirm that I was uploading to the directory to which I think I'm uploading. I'd try providing put with an absolute path (incl file name) as the second argument.
      Very nice idea, but it did not work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://702728]
Approved by Corion
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-03-28 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found