macdunn Posted July 9, 2004 Share Posted July 9, 2004 Next topic from me -- how do we use PHP or JavaScript to transfer a file from the server to the client drive. I have had no real problem using FTP_GET to transfer a file around the server where the PHP / FTP program is running. (Though, I did not think at first that I would need to enable Write privileges on the sub-directory where I had the PHP program, just assumed it was given.)I have searched with Google and read about 40 of the 900+ listings, all of which use the same two examples for FTP_GET, and I have checked a couple of forums, such as DevArticles (where the topic has been brought up with no answer). I am managing some files that cannot be displayed in a browser, such as TIFFs, where you would ordinarily right-click and select Save As...NOTE: I should also mention that a common example on the 'net shows that the destination file name includes C:\ as in "c:\testFile.txt". Do NOT include it. I included it in a test file name and ended up with a file named C: estFile.txt that I cannot delete from the directory. I am not a Linux/Unix head, just 20+ years in the DOS, Windows, Macintosh world (at MicroPro [yes, supporting WordStar 3.31], Broderbund, Borland, Novell, Tandem, etc.). So, I am not sure what the restriction is, probably should have used double-slash, but the PHP code did not burp.TIA,-Mac- Quote Link to comment Share on other sites More sharing options...
teacher Posted July 9, 2004 Share Posted July 9, 2004 I don't know much about this, but under quick functions in "PHP Your Visual Blueprint for Creating Open Source, Server-side Content" :Web sourceThis is what I find in the Quick Reference: ftp_get(ftp_stream, local_file, remote_file, mode) downloads a file from an FTP server. ftp_fput(ftp_stream,remote_file, fp, mode) Uploads a file. ftp_login(ftp_stream,username, password) logs into an FTP connection. (ftp_mkdir(ftp_stream, directory) makes a directory on an FTP server.I don't know if any of this helps you as I have never tried this but here it is.Julia Quote Link to comment Share on other sites More sharing options...
epp_b Posted July 9, 2004 Share Posted July 9, 2004 Um...why not just link to the files??? Quote Link to comment Share on other sites More sharing options...
macdunn Posted July 10, 2004 Author Share Posted July 10, 2004 Hi Julia.Thanks for your input, but the information that you referenced is clear to me. The FTP_GET and all other FTP get functions only transfer to the 'server.' It is so weird that there is nothing that handles to the client (your personal computer). I expect that transferring to the client is going to require a custom library.-Mac- Quote Link to comment Share on other sites More sharing options...
epp_b Posted July 10, 2004 Share Posted July 10, 2004 Hi Julia.Thanks for your input, but the information that you referenced is clear to me. The FTP_GET and all other FTP get functions only transfer to the 'server.' It is so weird that there is nothing that handles to the client (your personal computer). I expect that transferring to the client is going to require a custom library.-Mac-I believe that this would be a breach of security. If this were possible, it would be far too easy to develop malicious code that could download a virus/trojan/worm to a user's hard drive. If you're looking to force the "Save As" box, this can be done with header() Quote Link to comment Share on other sites More sharing options...
teacher Posted July 10, 2004 Share Posted July 10, 2004 I thought the very first one would do that: ftp_getI don't find any other references and wonder if you have tested it to see if it works? Julia Quote Link to comment Share on other sites More sharing options...
littlebone Posted July 10, 2004 Share Posted July 10, 2004 Next topic from me -- how do we use PHP or JavaScript to transfer a file from the server to the client drive. I have had no real problem using FTP_GET to transfer a file around the server where the PHP / FTP program is running. (Though, I did not think at first that I would need to enable Write privileges on the sub-directory where I had the PHP program, just assumed it was given.)I have searched with Google and read about 40 of the 900+ listings, all of which use the same two examples for FTP_GET, and I have checked a couple of forums, such as DevArticles (where the topic has been brought up with no answer). I am managing some files that cannot be displayed in a browser, such as TIFFs, where you would ordinarily right-click and select Save As...NOTE: I should also mention that a common example on the 'net shows that the destination file name includes C:\ as in "c:\testFile.txt". Do NOT include it. I included it in a test file name and ended up with a file named C: estFile.txt that I cannot delete from the directory. I am not a Linux/Unix head, just 20+ years in the DOS, Windows, Macintosh world (at MicroPro [yes, supporting WordStar 3.31], Broderbund, Borland, Novell, Tandem, etc.). So, I am not sure what the restriction is, probably should have used double-slash, but the PHP code did not burp.TIA,-Mac-Just a quick note on the file you cannot delete:You are correct, the "C:\testfile.txt" should have been specified as "C:\\testfile.txt" in Javascript. You ended up with a tab character in the file name (C:{tab}estfile.txt). I guess the OS in it's infinite wisdom cannot deal with this internally.However, you should be able to delete the file from a shell (I am guessing you are in windows wherethat would be a command box, CMD.EXE). Just go to the root directory and type: DEL *estfile.txt. Quote Link to comment Share on other sites More sharing options...
macdunn Posted July 10, 2004 Author Share Posted July 10, 2004 Hi Techie Wannabe,It is not a security issue. It is as if you are to use an FTP program, but do not want to give the visitor access to your FTP login info. The FTP commands allow the programmer to provide the visitor with the ability to upload without disclosing the login info. And FTP_GET allows a download to the server. Why not provide the programmer with the means to give the user a download to the client drive, controlled by the visitor, not pushed on to the visitor's hard by the program.Hi Julia, Obviously you have not tried to use the FTP_GET or FTP_FGET to 'download' files. Try to do it yourself. -Mac- Quote Link to comment Share on other sites More sharing options...
macdunn Posted July 10, 2004 Author Share Posted July 10, 2004 Thanks,You are right that I am working from a Windows client system and connecting to a Linux server. I do not go to the root often and had forgotten. No problems when I was running Apache on my Windows box, but on the Linux, got this mistake. Ain't cross-platform fun!The problem came from the sample code from Mitchell Harper on DevArticles.com titled 'Building An FTP Client With PHP.' I have gotten the answers I have looked for for a long time about Blob fields and FTP from his articles there (as pointed out to me on the forum here), but in both cases, he has mistakes in his code, in this case leaving a dropping that has to be cleaned up (is it okay to say that?). His articles are worth learning from ... with caution.Thanks again to all for sharing, regardless of the results, and thanks to Scot!-Mac- Quote Link to comment Share on other sites More sharing options...
epp_b Posted July 10, 2004 Share Posted July 10, 2004 If you're looking for a way to password-protect files, there's a better way to do that.If you're running Apache, you can create simple .htaccess and .htpasswd files that will do that. Quote Link to comment Share on other sites More sharing options...
macdunn Posted July 10, 2004 Author Share Posted July 10, 2004 If you're looking for a way to password-protect files, there's a better way to do that.If you're running Apache, you can create simple .htaccess and .htpasswd files that will do that.Hi Techie Wannabe,Nope, as I keep saying, I want to write a PHP program that will let a visitor download files to their client machine. Just that, no protection, no sneakie downloads, all I want is to give them a list of files, they select and the program downloads TO the CLIENT, NOT to the SERVER.Thanks anyway,-Mac- Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.