如果从带有变量的php运行,则命令不起作用。但是,如果我在没有变量的情况下从终端或php(exec或shell_exec)运行它,它就可以工作了。这不起作用:
$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))->打印:空
这项工作:
$command = 'lftp -c "open -u user,password -p 6710 sftp://xx.xx.xx.xx; put -O /folder1 folder2/file.txt;"';
exec($command);
感谢
在php.net 上找到
http://php.net/manual/fr/ftp.examples-basic.php
使用ftp_ssl_connect连接ssl ftp服务器和cd/ls/put etc unstead尝试exec/shell_exec命令行
// 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);
感谢gmaildot.com的kanedotprajakta写下这个例子。