labby
labby

Reputation: 31

ssh2_scp_send file is not copied, no errors

Though connection works ssh2_scp_send is not copying file (pdf).

To check connection I checked if source file is existent and I also tested and used successful:
- ssh2_sftp_mkdir
- ssh2_scp_recv

Here is my php code:

$my_sftp = parse_ini_file(config/sftp.ini.php');
$open_file = fopen($contract_pdf_path.$contract_pdf_name, 'r');

$destination = $my_sftp['sftp_root_to_dir'].'auftrag/'.$contract_pdf_name;              
$connection = ssh2_connect($my_sftp['sftp_host'], $my_sftp['sftp_port']);
            ssh2_auth_password($connection,$my_sftp['sftp_user'], $my_sftp['sftp_password']);

$sftp = ssh2_sftp($connection);

$result = ssh2_scp_send($connection, $contract_pdf_path.$contract_pdf_name, $destination, 0644);

I checked $result and got 1, as described I tested successful with other functions.

Anybody any idea?

Upvotes: 2

Views: 565

Answers (1)

labby
labby

Reputation: 31

To whom it may concern (or is interested):
Got some hints on another forum:

$my_sftp = parse_ini_file('config/sftp.ini.php');
$destination = $my_sftp['sftp_root_to_dir'] . 'auftrag/' . $contract_pdf_name;
$connection = ssh2_connect($my_sftp['sftp_host'], $my_sftp['sftp_port']);
ssh2_auth_password($connection, $my_sftp['sftp_user'], $my_sftp['sftp_password']);
$sftp = ssh2_sftp($connection);
$sftpStream = fopen('ssh2.sftp://'.intval($sftp).$destination, 'w');
fwrite($sftpStream,file_get_contents(realpath( $contract_pdf_path.$contract_pdf_name)));
fclose($sftpStream);

And this one works :-)

Upvotes: 1

Related Questions