当前位置: 动力学知识库 > 问答 > 编程问答 >

php - PHPSecLib: Executing scp on remote server to another remote server terminates early?

问题描述:

I'm attempting to copy a file between two remote servers via PHP using PHPSecLib.

SSH Keys exist between domain.tld and domain2.tld, and locally performing this SCP from domain.tld works fine.

Trimmed down version of my code:

echo "Copying file... ";

$ssh = new Net_SSH2('domain.tld');

$ssh->enableQuietMode();

$ssh->login('user','pass');

$ssh->exec("scp /home/file.tar.gz [email protected]:/home/file.tar.gz");

if($ssh->getExitStatus())

exit("Failed at line: ".__LINE__);

echo "Done!\n";

In the example above, the script would finish after 5 seconds, echoing "Done!" at the end, however the copy has not completed and is still running for approx another 2 minutes.

Unfortuantely, I wish to remotely do things with the file that is being copied in this manner, thus waiting for it to complete is necessary.

I've investigated using PHPSecLib Net_SCP as well, unfortunately this cannot perform a remote -> remote copy, and I need to avoid using the local server as an intermediary for the copy process (Due to distance/bandwidth constraints).

I've attempted to re-write the above using $ssh->read() and $ssh->write(), however with limited understanding of how these procedures are supposed to work, I had no success.

Is anybody able to shine some light on this issue for me?

网友答案:

Answered the problem myself. It turns out that Net_SSH2 will automatically timeout an exec if no STDOUT is received within a default value. The answer was to call $ssh->setTimeout(60000) (or some other equally ridiculous number) before the exec statement.

网友答案:

Are you using public key auth? If you're using password auth then you'd need an interactive prompt. Or you could use the sourcefile attribute too.

I tried it just now using public key auth and it worked just fine.

分享给朋友:
您可能感兴趣的文章:
随机阅读: