2

Command does not work if run from php with variables. But if I run it from the terminal or from php (exec or shell_exec) without variables it works. This not works:

$command = 'lftp -c "open -u'.$user.','.$password.' -p xxx sftp://xx.xx.xx.xx; put -O /folder1 folder2/'.$fileName.';"';
exec($command);

var_dump(shell_exec($command)) -> print: NULL

This works:

$command = 'lftp -c "open -u user,password -p 6710 sftp://xx.xx.xx.xx; put -O /folder1 folder2/file.txt;"';
exec($command);

Thanks

mstafkmx
  • 419
  • 5
  • 17
  • There's a lot of similar questions. I'd recommend searching. For example: https://stackoverflow.com/questions/8527817/updated-php-exec-system-or-passthru-all-remove-single-or-double-quotes, https://stackoverflow.com/questions/6780285/php-shell-exec-not-printing-dynamic-output-only-prints-static-echo-text?rq=1, https://stackoverflow.com/questions/20107147/php-reading-shell-exec-live-output, etc – Meetai.com Apr 29 '15 at 23:05

1 Answers1

-1

Finded on php.net

http://php.net/manual/fr/ftp.examples-basic.php

use ftp_ssl_connect to connect ssl ftp server and cd/ls/put etc unstead trying to exec / shell_exec command line

// set up basic connection 
$ftp_server = "example.com"; 
$conn_id = ftp_ssl_connect($ftp_server); 

// login with username and password 
$ftp_user_name = "myuser"; 
$ftp_user_pass = "mypass"; 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
ftp_pasv($conn_id, true); 
// check connection 
if ((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!"; 
        echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        exit; 
    } else { 
        echo "Connected to $ftp_server, for user $ftp_user_name"; 
    } 

$buff = ftp_rawlist($conn_id, '.'); 
var_dump($buff); 
ftp_close($conn_id);

Thanks to kane dot prajakta at gmail dot com who write this example.

Hino
  • 1
  • 2