[Klug-general] PSCP from Windows to Linux via PHP

MacGyveR macgyver at thedumbterminal.co.uk
Fri May 6 20:07:36 UTC 2011


On Thursday 05 May 2011, Nathan Friend wrote:
> Afternoon KLUG,
> I'm using a PHP script to copy a file from a Windows machine to a Linux
> machine.
>
> I found PSCP, a windows version of SCP
> (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
> which works perfectly from the Windows CLI.
>
> Unfortunately when I run it from a PHP script it just hangs at the
> PSCP commend.  No errors in the Apache log, so I guess it's waiting
> for something.
>
> <?php
> exec('c:\apps\pscp -q -i c:\key\akeyfile.ppk c:\source_file.txt
> user at linuxbox:/destination/');
> ?>
>
> I'm using key files to prevent a password prompt and the -q switch to
> suppress output.
>
> Any ideas?
>
> Cheers,
>
> Nathan.
>
> _______________________________________________
> Kent mailing list
> Kent at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/kent

Nathan,
  Did you try running the PHP script from the CLI? Also when using exec, you 
should direct the output somewhere for debugging/error handling:

$output = array();	//all output to stdout goes here
$retVal = null;	//exist status of command
$lastLine = exec('c:\apps\pscp -q -i c:\key\akeyfile.ppk c:\source_file.txt 
user at linuxbox:/destination/ 2>&1', $output, $retVal);	//redirect stderr to 
stdout
echo "Return code from cmd: " . $retVal . PHP_EOL;
var_export($output);	//have a look at the output

There are more problems when running this sort of task from a webserver; If 
the command takes too long then apache or your browser will timeout. If you 
are running in safe mode you will have to modify your php config to allow 
execution of binaries in non-standard locations.



More information about the Kent mailing list