1

I'm building a website. I have the SFTP login credentials for the server.

I'm trying to make it so that a user can select a file on their hard-drive, and upload the file to a remote computer through SFTP.

Is this possible? How would I do this?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Diego
  • 161
  • 1
  • 1
  • 10
  • 1
    My original title was "Transfer a file from website through sftp to another computer". This new title may be more technically correct, but those are not the words I used when searching for an answer to my question. Hopefully google will pick this up, so that other people who don't know what they're doing, like myself, are able to find it even if they don't know the precise language. – Diego May 26 '15 at 17:02

2 Answers2

2

I assume you use (or can use) PHP. You didn't specify, what technology you are using.

Start with reading:

That combined together gets you a code like:

include('Net/SFTP.php');

$uploaded_file = $_FILES["attachment"]["tmp_name"];

$sftp = new Net_SFTP("example.com");
if (!$sftp->login('username', 'password'))
{
    die("Connection failed");
}

$sftp->put(
    "/remote/path/".$_FILES["attachment"]["name"],
    file_get_contents($uploaded_file));

This is a very simplified code, lacking lots of validation and error checking.

The code uses the phpseclib library.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
-1

If you are in Windows, you can use a FTP Client like WinSCP... If you are in Linux, use te SCP command:

scp /home/me/myfile.dat user:password@remoteserver:/remotedir

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I'm not trying to upload a file from my own computer one time. I'm building a website. This process needs to be automated to upload files from random people. – Diego May 22 '15 at 18:52
  • Ooopss, depends of the language you are using... You should try PHP and the [ssh2_sftp](http://php.net/manual/es/function.ssh2-sftp.php) Check this [another question](http://stackoverflow.com/questions/9572314/uploading-files-with-sftp) – gomezbjesus May 22 '15 at 19:57