BentCoder
BentCoder

Reputation: 12740

Transferring a file from local Linux server to remote Linux server over SFTP

I can transfer a file from one folder to another on same computer with the code below which works file.

$file = 'pdf.pdf';
$source_path = 'source/';
$target_path = 'target/';

if (! copy($source_path . $file, $target_path . $file))
{
    exit('Failed to copy ' . $source_path . $file);
}

echo $source_path . $file . ' file copied to ' . $target_path . $file;

What I want to do it to transfer same file to remote linux server which uses SFTP-SSH so how do I do it? If anyone ask, I found a lot of examples to understand the logic with cURL(), ftp_get(), stream_copy_to_stream(), ssh2_sftp(), scp() but failed to accomplish it since never done it before.

Note: My settings below works fine for FileZilla.

target host: https://192.168.32.1/test_folder/
target host: https://mysite.site.com/test_folder/
protocol: SFTP-SSH
port: 2281
username: myusername
password: mypassword

Thanks

Upvotes: 1

Views: 428

Answers (1)

Leo Nyx
Leo Nyx

Reputation: 696

I never tried it myself, but phpseclib seems quite promising: http://phpseclib.sourceforge.net/sftp/examples.html#put

Upvotes: 1

Related Questions