2
votes

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

1
There's a lot of similar questions. I'd recommend searching. For example: stackoverflow.com/questions/8527817/…, stackoverflow.com/questions/6780285/…, stackoverflow.com/questions/20107147/…, etc - Meetai.com

1 Answers

-1
votes

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.