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

Re: Net::FTP failure

by kabeldag (Hermit)
on Jul 06, 2008 at 02:03 UTC ( [id://695776]=note: print w/replies, xml ) Need Help??


in reply to Net::FTP failure

Put is part of Net::FTP. Got any code or actual error message(s). Did you run it with the Debug=>1 option?

Update: Just taking a wild guess here, but the 'put' command from your ftp client script maybe failing because it's running in *passive* mode, as Net::FTP seems to by default. The server probably doesn't want *passive* connections, and is only accepting *active*.

As an example to specify passive or not in your script (and use the debug option):

use Net::FTP; $ftp = Net::FTP->new('your.ftp.server', Debug => 1, Passive=>0) or die "Cannot connect to your.ftp.server: $@"; $ftp->login("user",'passwd') or die "Cannot login ", $ftp->message; $ftp->cwd('a.remote.directory') or die "Cannot change working directory ", $ftp->message; $ftp->put('./my.local.file.in.the.lcwd') or die "put failed ", $ftp->message; $ftp->quit;

Replies are listed 'Best First'.
Re^2: Net::FTP failure
by wow_za_ (Initiate) on Jul 06, 2008 at 21:46 UTC
    Below is the output, followed by the script when it is run.


    Name "main::path2" used only once: possible typo at transfer.pl line 38.
    Net::FTP>>> Net::FTP(2.75)
    Net::FTP>>> Exporter(5.58)
    Net::FTP>>> Net::Cmd(2.26)
    Net::FTP>>> IO::Socket::INET(1.27)
    Net::FTP>>> IO::Socket(1.28)
    Net::FTP>>> IO::Handle(1.24)
    Net::FTP=GLOB(0x180bc60)<<< 220 unixs1.cis.pitt.edu FTP server ready. Connected!
    Net::FTP=GLOB(0x180bc60)>>> user mcs2
    Net::FTP=GLOB(0x180bc60)<<< 331 Password required for mcs2.
    Net::FTP=GLOB(0x180bc60)>>> PASS ....
    Net::FTP=GLOB(0x180bc60)<<< 230 User mcs2 logged in.
    Login successful
    Net::FTP=GLOB(0x180bc60)>>> CWD ./public/html/
    Net::FTP=GLOB(0x180bc60)<<< 250 CWD command successful.
    Net::FTP=GLOB(0x180bc60)>>> PWD
    Net::FTP=GLOB(0x180bc60)<<< 257
    "/afs/pitt.edu/home/m/c/mcs2/public/html" is current directory.
    pwd = /afs/pitt.edu/home/m/c/mcs2/public/html
    Net::FTP=GLOB(0x180bc60)>>> HELP PUT
    Net::FTP=GLOB(0x180bc60)<<< 502 Unknown command PUT.
    Supported = 0
    Net::FTP=GLOB(0x180bc60)>>> PORT 10,0,1,196,207,163
    Net::FTP=GLOB(0x180bc60)<<< 502 Illegal PORT Command
    Could not send file!




    #################################################

    #!/usr/bin/perl -w

    #this library is needed for the transfer
    use Net::FTP;


    #declares your host and creates your ftp object
    $host='unixs.cis.pitt.edu';
    $ftp=Net::FTP->new($host,Timeout=>240,Debug=>1,Passive=>0, Port=>21) or die "Could not create FTP object!\n\n";
    print "Connected!\n";


    #THIS IS THE LOGIN SECTION, REPLACE $uname AND $pwd WITH EITHER A USERNAME
    # AND PASSWORD, OR DEFINE THE VARIABLES YOURSELF IN THE LINES BEFORE

    ($uname, $pwd) = get_info();

    $ftp->login($uname,$pwd) or die "Cannot login to $host!\n\n";
    print "Login successful\n";

    #this line will change to whichever directory you need
    $dir = "./public/html/";
    $ftp->cwd($dir) or die "Unable to switch directories!\n\n";

    $pwd = $ftp->pwd();
    print "pwd = $pwd\n";



    $test = $ftp->supported("put");
    print "Supported = $test\n";



    #@files = $ftp->dir();
    #print "Files = $files[0]\n";


    #uploads the file, absolute path names required.
    #path1 is the file path, path2 is the location on the remote host

    $path1 = "test.html";
    $path2 = "./test.html";

    #$path2 = "/afs/pitt.edu/home/m/c/mcs2/public/html/test.html";

    $ftp->stor($path1) or die "Could not send file!\n\n";
    print "File transferred!\n";

    #quits the connection
    $ftp->quit or die "Unable to close the connection?\n\n";
    print "Finished!\n";

    exit(0);
      1. What happens if you - in your MANUAL ftp session - type the HELP PUT? Do you get the same error message?

      2. What output do you get if you leave your script using the default passive mode?

      3. Is there any NAT going on?

      The server doesn't implement a 'put' command, the client does.
      The supported() method is for checking what RAW commands the server supports.

      Things like these:
      The following commands are implemented. USER EPRT STRU ALLO DELE SYST RMD MDTM PASS EPSV MODE REST CWD STAT PWD PROT QUIT LPRT RETR RNFR LIST HELP CDUP PBSZ PORT LPSV STOR RNTO NLST NOOP STOU AUTH PASV TYPE APPE ABOR SITE MKD SIZE
      Let me update:

      To be more specific and make more sense, the supported() method checks if the server supports the actual *raw* command. See this link: FTP Command Aliases

        1. D'oh - you are quite right - was so carried away by the error message.

        Questions 2 & 3 are still worth answering, though?

      Perhaps I am misreading this code or this entire thread but you appear to be using the stor method

      stor ( FILE ) Tell the server that you wish to store a file. "FILE" is th +e name of the new file that should be created.

      Perhaps you should try the put method ?

      put ( LOCAL_FILE [, REMOTE_FILE ] ) Put a file on the remote server. "LOCAL_FILE" may be a name + or a filehandle. If "LOCAL_FILE" is a filehandle then "REMOTE_FILE" + must be specified. If "REMOTE_FILE" is not specified then the file will be stored + in the current directory with the same leafname as "LOCAL_FILE". Returns "REMOTE_FILE", or the generated remote filename if +"REMOTE_FILE" is not given. NOTE: If for some reason the transfer does not complete and + an error is returned then the contents that had been transfered will + not be remove automat&#8208; ically.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://695776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-20 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found