How to upload a file to another server using cURL and PHP?

How do I upload files to a SFTP server using PHP and JavaScript?

  • I want to allow people to upload files to a SFTP server. I quite new to PHP and JS, so a generic code example can help. Thanks.

  • Answer:

    Your goal is not totally clear to me. You do not need Javascript to upload a file. As far as I know you can not use an HTML page to upload a file to an sftp server. You can however, use an HTML page to upload a file to your webserver and further upload the file (after checking) to your file server by first opening an SSH connection using ssh2_connect() and connecting to your sftp server with ssh2_sftp(). Then you can use the connection as a semi-mounted drive. Check http://php.net/manual/en/function.ssh2-sftp.php for more info

Maarten Wolzak at Quora Visit the source

Was this solution helpful to you?

Other answers

try system()

Zhang Rentian

Hi there,Your question is a bit unclear, but I’ll try to answer it according to what I’ve understood from it. There comes two different in my mind and those are, how do I let people upload a file to my site. That is quite simple. Have a form which will have a file tag and let them upload a file. For that you can check out https://github.com/blueimp/jQuery-File-Upload.The second question which comes to me is that, you want people to upload files, but you don’t want to save them to your server, instead to another server. As far as I know, you need permission to upload file to another server. For example, if you want to upload your files to a server like rackspace, they have exposed some services which is written in PHP. You can use that to fulfill your needs.I hope I’ve answered your question.

Shah Mubashir

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.