-1

Possible Duplicate:
How to SFTP upload files from PHP

I have two files:

  • upload.php
  • data.csv (around 1MB)

Upload.php should connect using SFTP and CURL and then send the data.csv file to their server. I have been given a URL, username and password so I can log-in using SFTP.


Can anyone tell me the code I should use? Unfortunately I have no real experience with CURL.

Thanks,

Ryan

Community
  • 1
  • 1
Ryan B
  • 21
  • 1
  • 6
  • is data.csv being generated by upload.php? or is upload.php doing nothing but the upload? if it's nothing but the upload, why not simply use the proper command-line sftp client instead of having to hack together far too much php? – Marc B Nov 20 '12 at 16:00
  • If it's really sftp (SSH File Transfer Protocol) would be better to use php ssh extension http://php.net/manual/en/book.ssh2.php – Zdenek Machek Nov 20 '12 at 16:03

1 Answers1

1

You can use SSH2 extension:

$host = 'domain.tld';
$username = 'username';
$password = 'password';
$connection = ssh2_connect($host);
if (ssh2_auth_password($connection, $username, $password)) {
  echo "Authentication Successful!\n";
} else {
  die("Authentication Failed...");
}
if (ssh2_scp_send($connection, '/local/filename', '/remote/filename')) {
  die("Upload Successful!\n");
} else {
  die("Upload Failed...");
}

Or you can check out this tutorial if you still prefer curl.

Sergey Eremin
  • 10,994
  • 2
  • 38
  • 44