Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Net::FTP failure

by wow_za_ (Initiate)
on Jul 06, 2008 at 21:46 UTC ( [id://695876]=note: print w/replies, xml ) Need Help??


in reply to Re: Net::FTP failure
in thread Net::FTP failure

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);

Replies are listed 'Best First'.
Re^3: Net::FTP failure
by zebedee (Pilgrim) on Jul 07, 2008 at 04:12 UTC
    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?

Re^3: Net::FTP failure
by kabeldag (Hermit) on Jul 07, 2008 at 08:40 UTC
    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?

        Well, the 502 Illegal PORT Command error is obviously holding up the data-connection portion of the FTP session.
        Your script is telling the server to send data from its FTP data-port (20 I assume) to your client's TCP port 53155.

        FYI, the Syntax of the PORT command: h1, h2, h3, h4, p1, p2. EG: Calculation of the local socket-port is done like this:
        p1*256+p2 = (207*256)+163 = 53155.

        It could be a privileged/restricted ports issue -- Though that would give a 'permission denied' error (I would have thought).

        For the record, 99% of all FTP data-connections are NAT/Firewall/socket-binding issues. Heh.

        You didn't state whether you were *actually* able to upload/download successfully via your system ftp program either.

        Google is good for FTP connection flow-charts etc...
Re^3: Net::FTP failure
by LesleyB (Friar) on Jul 07, 2008 at 13:02 UTC

    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://695876]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-24 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found