1

I tried to costumize the filename in php and transfer it via ssh, unfortently my code not work with uniqe filenames.

$con = ssh2_connect('142.132.165.XXX', 22);
ssh2_auth_password($con, 'root', 'XXXX');
$filename = uniqid('timetrac', true) . '.sql';
echo $filename;
$rd = '/root/ficken/';
$lf = 'timetrac.sql';
$bname = $finfo->getBasename($filename);
$sftp = ssh2_sftp($con);
ssh2_scp_send($con, $lf, '/root/test/'&$filename);

How I can costumize the filename?

ndm
  • 59,784
  • 9
  • 71
  • 110
Okan
  • 19
  • 6
  • What is the exact error you are getting from trying to upload the file? It can be related to the file permission issue. – harish durga Jan 26 '22 at 12:40
  • Well I tried to transfer SQL dump, unfortunately I did know errors.just a clean white page.if I look on the server file is not generated. I tried to generate a better file with timestamp or unique IDs.have you any idea how I can do that without using PHPseclib? Sincerely Okan – Okan Jan 26 '22 at 13:18
  • If you're supposed to be getting output and you're getting just a blank white screen, you may be getting a 500 Internal Server Error. Check your server logs for any errors or information. – aynber Jan 26 '22 at 13:25
  • 1
    `'/root/test/'&$filename` is interesting syntax. It doesn't look correct to me, but PHPStorm isn't throwing an error. The `&` is usually a bitwise operator or for passing by reference, and it looks like you're attempting to use it to concatenate the string. – aynber Jan 26 '22 at 13:28
  • I think also syntax not right, but I tried in many different ways before I settle up this question. Actually I need a way to catch the base name from the file and customise it. Like in the following links. https://stackoverflow.com/questions/20859628/how-to-separate-filename-from-path-basename-versus-preg-split-with-array-po https://stackoverflow.com/questions/1049949/combine-directory-and-file-name-in-php-equivalent-of-path-combine-in-net But I'm not completely sure how I can do that in my case. – Okan Jan 26 '22 at 13:41

0 Answers0