Jump to content

Recommended Posts

I'm experimenting with different options for ftp and want to use my personal fave ftp tool - ncftp.  I like ncftp because it's very fast, very simple and has 11 well-documented exit codes.

 

I want to run it from a php script and then return the exit code to a web page live report.  I've looked at exec() which works and so I'm happy with that, but how do I get the exit code?  I can do it in VBS easily and do so a fair bit, but I'm still very much learning with php.

 

Looked at return() and exit() but not sure they are what I want.  Can anyone throw any light on this for me please or point me in the right direction?

 

(PHP running under WAMP 1.7.0 on Windows Server 2003)

 

Many thanks.

Here's a bit more info...

 

Simple script is as follows (the exit code mappings are standard ncftp, btw and what I want to display on screen.):

 

<?php

 

$cmd = '"ncftpput" -u linktest -p linktest 192.168.0.10 / C:\wamp\www\ftp\test.txt';

$nftp = exec($cmd,$output);

 

if ($output == "0") $output = ("Success");

if ($output == "1") $output = ("Could not connect to remote host.");

if ($output == "2") $output = ("Could not connect to remote host - timed out.");

if ($output == "3") $output = ("Transfer failed.");

if ($output == "4") $output = ("Transfer failed - timed out.");

if ($output == "5") $output = ("Directory change failed.");

if ($output == "6") $output = ("Directory change failed - timed out.");

if ($output == "7") $output = ("Malformed URL.");

if ($output == "8") $output = ("Usage error.");

if ($output == "9") $output = ("Error in login configuration file.");

if ($output == "10") $output = ("Library initialization failed.");

if ($output == "11") $output = ("Session initialization failed.");

 

echo $output;

 

?>

 

The idea is to display the output live in a web page.  However I just get a blank page.  The file copies perfectly, if I use "-d stdout" and pipe it to a text file it all looks good, but in the browser I just get 'Array'. 

 

If I echo $nftp I get the last line of the conversation - "221: Goodbye".

 

You never know - this may help someone else too.  :0)

Now running the above code as a function;

 

<?php

...

function nftp($server)

{

exec($cmd,$output);

.. <code above> ..

 

and then to see what's coming back at me I've added this at the end:

 

$key = array_keys($output);

$keys = print_r($key);

Return $keys;

}

 

-  So now for a successful ftp transfer I get

 

Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 ) Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 ) 1

 

If I put a non-existent IP address :

 

$server = "192.168.0.3";

nftp($server);

print nftp($server);

 

I get:

 

Array ( [0] => 0 [1] => 1 ) Array ( [0] => 0 [1] => 1 ) 1

 

(without the bullet points btw!)

 

Been playing all afternoon, still no further on.  Any help greatly appreciated.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.