Question

I'm new to PHP. I have the below details of my server. Now I need to upload (or move) a .sql file to the server from localhost application using SFTP. I've tried many and ended up with failures.

  • Hostname
  • Port Number
  • Username
  • Password
  • Location

Please anyone give me a simple example to connect SFTP connection to my server to upload a file.

Was it helpful?

Solution

If you just want to transmit a file and don't care about using scp or sftp, then I would encourage you to use scp. Here comes a basic example (taken from the PHP manual):

$connection = ssh2_connect('www.example.com', 22);
if($connection === FALSE) {
    die('Failed to connect');
}

$state = ssh2_auth_password($connection, 'username', 'password');
if($state === FALSE) {
    die('Failed to authenticate');
}

$state = ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
if($state === FALSE) {
    die('Failed to transfer the file');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top