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

1

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer does not address the question mstafkmx asked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.