1

I would like to know that is there any possibility where we can able to directly post the file in Remote FTP server.

For achieving my need, I have checked that html form control supporting FTP protocol in Action attribute so which i have tried and below is the code snippet.

<form id="myform" method="post" enctype="multipart/form-data" action="ftp://username:password@domainname">
    <table style="border-collapse: collapse;" border="1" width="500px">
        <tbody><tr>
            <td> Upload File :</td>
            <td><input name="uploadedfile" type="file"></td>
        </tr>
        <tr>
            <td colspan="2">
             <input name="Save File" value="Save File on FTP Server" id="submit" type="submit">
            </td>
        </tr>     
    </tbody></table>
</form>

But when i am uploading the file and submitting the form then browser do the authentication of the FTP which i have mentioned in action attribute and after success it directly redirect me in mentioned domain with file manager view that means i can see the files and folders which hosted in the mentioned FTP domain.

I am sure that as form is successfully submitted then somewhere the uploaded file transfer in FTP server but where that i don't know.

Also if the HTML support the FTP protocol in action attribute then there should some way to post the file directly in FTP server.

Looking forward for some direction on this.

Thanks in advance.

user2746557
  • 81
  • 1
  • 9

2 Answers2

2

This isn't possible. Some browsers support reading from FTP. HTML forms provide no mechanism to send files to FTP. JavaScript options can't upload to FTP since there is no mechanism in the FTP protocol to bypass the Same Origin Policy.

You need to upload the file somewhere with HTTP and deal with it using server side code.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • if HTML forms provide no mechanism for send files to FTP then why it allow the FTP protocol in action attribute ? what's the purpose of FTP protocol in form action attribute ? – user2746557 Aug 13 '15 at 09:46
  • If you are planning to just upload the file to the FTP then you just need to mention the location of the FTP as the _upload path_ of the file. – Puttaa Aug 13 '15 at 09:48
  • 1
    Because the specification only says that the `action` attribute should contain a URL. (In theory, a GET form could submit data to an non-HTTP URL, although file uploads wouldn't be possible then). There is no point in specifying an FTP URL there, the HTML spec just fails to stop you shooting yourself in the foot if you try. – Quentin Aug 13 '15 at 09:48
  • @Puttaa — That doesn't make any sense. – Quentin Aug 13 '15 at 09:48
  • @Quentin, thanks for your directional response. So now i have to find the alternative because i don't want to do like first transfer file through http protocol in website server and then further transfer in FTP server as it will take double time if user will upload the 100 MB file. Is there anyway i can do like transfer the bytes by bytes which copied in temporary location of the server instead of waiting full file getting transfer and then transfer in FTP server. – user2746557 Aug 13 '15 at 09:54
  • @Quentin An FTP must be present on a server, right? and if your are trying to interact with the FTP with a PHP you need a server. So why cannot be the upload path of the file be hard coded? – Puttaa Aug 13 '15 at 09:54
  • @Puttaa — What does PHP have to do with it? – Quentin Aug 13 '15 at 09:55
  • @Quentin Can we post a file directly from an HTML form to the FTP without the use of any server side coding? – Puttaa Aug 13 '15 at 09:57
  • @Puttaa — No. But having established that, you seem to have gone and answered a completely different (and rather trivial) question that (a) is just one of several dozen things that would have to be done in PHP and (b) nobody asked. – Quentin Aug 13 '15 at 09:59
  • @Quentin I am not as experienced as you are, i was just trying to explore the things coz i developed one for myself where I uploaded the images to the FTP using the PHP. and I am sorry if I apprehended it wrong. – Puttaa Aug 13 '15 at 10:01
  • @Quentin, do you have any idea about "So now i have to find the alternative because i don't want to do like first transfer file through http protocol in website server and then further transfer in FTP server as it will take double time if user will upload the 100 MB file. Is there anyway i can do like transfer the bytes by bytes which copied in temporary location of the server instead of waiting full file getting transfer and then transfer in FTP server." – user2746557 Aug 13 '15 at 10:23
  • @user2746557 — Forget FTP entirely. Run an HTTP server on a machine with access to the disk that you want to save the file to. – Quentin Aug 13 '15 at 10:25
0

You just can't submit to ftp server you have to interact with ftp using php

Here is a similar question Upload single image file to FTP using PHP

& here is an example on how to upload to a ftp server using php from php.net

Community
  • 1
  • 1
ARIF MAHMUD RANA
  • 5,026
  • 3
  • 31
  • 58