hi,

Do anybody knows how can I create a new file on an existing opened FTP account?

I am building an FTP client using PHP but there is no FTP function for creating a new file on the server.

If there is no way, can I create a new file using the file functions on my FTP server?

thx.

    Why would you want to? I don't recall "create a file" ever being part of the file transfer protocol. I guess if you had some stuff and you wanted to save it on an ftp server, you could save it in a local file first and then just put that on the ftp server (as the protocol specification notes "A new file is created at the server site if the file specified ... does not already exist.").

      thx Weedpacket

      I believe that there is no way to achive this (creating a file on a remote server through an open FTP connection).

      But why I need this? I am currently developing a web content management system with a full features, and I think creating a new file on the server is an important issue.

      Also I couldn't be able to copy and edit files online!!!

      Thank you.

        That's about the worst method in the world to do what you want.

        And like Weedpacket said, FTP is a transfer protocol.

        It is not a maintenance system.

          you could try makeing a 0 byte file on your web server, then use ftp_put().

          eg

          ftp_put($conn_id, $NewFileName, "/path/to/temp/file", FTP_ASCII);
          

          this would copy the temp file to your ftp account and rename it in the process.

          By the way what is the use in replying to a message with only destructive critisism in place where there should be constructive help?

          The simple matter is that you look at any ftp client and they all have an option to create a file, so why should a web based ftp client be any different. I like your idea jaddy, good luck with it!

            Originally posted by marque
            you could try makeing a 0 byte file on your web server, then use ftp_put().

            Effectively what I suggested, without the "0-byte" requirement. I don't see the point of using ftp to transfer a 0-byte file to the server, since about the only things you could do with that file via ftp are (a) transfer it to another machine and whose going to have an urge to download an empty file? (b) delete it (waste of time putting it there, then), and (c) replace it with another file (ditto).

            The simple matter is that you look at any ftp client and they all have an option to create a file, so why should a web based ftp client be any different.

            Really? Let's see what I've got ... no, none there ... nope, nor that one ... no .... Check the specification .... nope, nothing in RFC0959 about "creating files" except as the result of a transfer or if the file is in fact a directory (for which there exists the MKD command).

              Ok I do stand corrected, i looked through 3 ftp clients, and none have the option to create a file. But that doesn't mean it's not usefull, (somehow).

              Creating a new 0 byte file probably wouldn't have any relevance at all. Perhaps the idea of creating a new text/html document and saving locally through fopen() and fwrite() then copying the file to the ftp server, and unlinking the file might prove to be worth while.

              I remember a web server that I had access to upload/edit/create my html documents through the web as well as ftp to the server through an ftp client. This is where it would come in handy.

                Thx,

                It works at last!!

                What I've did exactly was using the function touch() to create a 0 byte file in my PC, then I've uploaded the file using the function ftp_put(). This achived what I need exactly (creating a new file on my web-based FTP client).

                I think editing pages got the same idea. You have to download the file first, do fwrite() to edit the content then upload the file. I don't know if there are any security holes by using those techniques!!

                Thank you marque for the constructive help, I really appreciate this kind of high spirit 🙂

                  Write a Reply...