I was trying to build an application that will download some files from various ftp servers to a local directory. Later I would upload them to other ftp servers.
The application is built using Zend framework.
The thing is I can't find a class to handle ftp download/upload functions in Zend framework.
The only class available is Zend_File_Transfer which has the following comment:
Note: Limitation
The current implementation of Zend_File_Transfer is
limited to HTTP Post Uploads. Other adapters supporting downloads and
other protocols will be added in future releases. Unimplemented
methods will throw an exception. For now, you should use
Zend_File_Transfer_Adapter_Http directly. As soon as there are
multiple adapters available you can use a common interface.
I need to be able to do the following:
Upload multiple files.
Get a remote directory listing of all files.
Set validators
Set filters
Set paths
Rename files
Wrapper for downloads
Exceptions for various errors during operation.
Is there a solution to this problem in Zend framework? Could you recommend an alternative library for ftp operations ?
Thanks in advance
UPDATE:
I checked the PEAR package and unfortunately it's still in alpha
release. Moreover their functions return errors not exception once a
problem occur like download failure or remote path weren't found.
Unfortunately Skjb_Ftp isn't complete as many functions don't have an implementation.
Check out this php5 wrapper for the builtin FTP functions: https://github.com/dg/ftp-php it has some exception handling stuff you might be able to use.
This is a fully OOP php ftp library i build it in my self (hard working), its unit tested and it will works for your purposes perfectly. php-ftp-client
Here is great library for it: https://github.com/Nicolab/php-ftp-client
There is a proposal for Zend_Ftp that you might be able to use. Failing that, there is Skjb_Ftp.
I cannot vouch for the completeness or validity of either of these solutions, as I haven't used either, but it should be something to get you started. Some of the functionality you require is missing, but it shouldn't be too difficult to add it using the FTP functions.
Related
I'm working with the Amazon SDK for PHP, which is a little over 2MB when extracted. I only need the functionality for S3.
Is it possible to extract only the required files for S3 from the SDK and use those? If so, which files do I need?
Thanks
Here's an almost-official answer from the AWS forums:
Hey! This is a feature we've been thinking about better supporting in the future, but right now, there is no official or supported way to do this. That said, I think you might be able to get away with keeping the following files for using only S3:
lib/cachecore/*
lib/dom/*
lib/requestcore/*
sdk.class.php
services/s3.class.php
utilities/*
You could also delete a few more items out of the of the utilities directory like the hadoop ones, manifest, stacktemplate, and stepconfig.
I successfully made a list_buckets call with just these files, but
obviously you are going to want to test all of your API calls to make
sure that they work and that you aren't missing any dependencies that
I might have overlooked. Good luck.
I used this dedicated class before http://undesigned.org.za/2007/10/22/amazon-s3-php-class and it did the job just fine
I searched over the Internet several documentation about how to create PHP extensions, but unfortunately, there is nothing about linking to another extensions (and making a requirement for having that extension loaded prior to the new it is being created).
I guess I could simply #include necessary header files into my source code, but not sure about linking.
As an example, and to play with extension creation, the first I want to create is a solution I implemented to allow namespaces in memcached github but wanted to know how to use other extensions' code from my custom extension one for other usages as well.
I'm not sure how to reply to the thread with StormByte, but it sounds like you need to do some load balancing or caching, not extending PHP.
If you really want to do this at the code level, you could use exec() to call a Python script, which gets compiled into byte code automatically.
I am in the process of migrating a lot of files in a large PHP application from local to remote storage. File operations are being transitioned using PHP stream wrappers as an intermediate solution so that we can easily change calls such as fopen('/local/file/path') to fopen('scheme://remote/file/path').
So far I've come across only one feature which is broken by this, which is the GD image library (its file write methods such as imagejpeg, imagegif and imagepng will not write to file streams).
In addition, PHP security options deny include() and require() calls on URLs.
I've tried looking for a list of known incompatibilities but can't find one.
I already have several workarounds available, so I'm covered there, and we'll perform extensive testing, but I would like to know in advance of any pain points if someone's been through the same process before.
Specifically, we are using PHP 5.3.6 on Debian Squeeze.
I would suggest reading this:
http://www.php.net/manual/en/class.streamwrapper.php
A lot of your answers will be found there.
Ok, just wondering on the versions of PHP that this class is built into. And if they are built into all platforms (OS's). I'm wanting an approach to search through a zip file and place files using file_put_contents in different filepaths within the webroot. In any case, I'm familiar with how to do this with the ZipArchive class, but I'm wondering if using this class would be a good solution and support MOST, if not ALL servers?? I mean, I'd rather not use a method that requires the Server to have it installed. I'm looking for a solution to this that will support at least MOST servers without having to install the class...
Thanks :)
Also, I'd like to support opening tar.gz and/or .tgz files if possible, but I don't think the ZipArchive class supports this, but perhaps a different built-in php class does??
Tar support is not built into PHP, but if you have a look at the PEAR library you should be able to find some classes that support creating/extracting tarballs (amongst others). Have a look at http://pear.php.net/package/Archive_Tar or http://pear.php.net/package/File_Archive. The last one should be a generic interface to multiple archiving formats (including ZIP and TAR).
Whether or not ZIP support is built-in may vary, though I guess most packagers will include it. Then again, you could always test it by checking if the ZipArchive class exists by calling class_exists('ZipArchive'); and show a nice error message or fall back to a more generic approach...
Is it possible to do file operations from a script running on a different server than the files being operated on? That is, upload, move, rename, delete, create new, modify, etc.
How would I go about doing this?
As far as I know, it can be done only by logging into the shell via the remote script and then executing the commands from within the shell, or maybe by using FTP from the remote script.
Another method would be:
Create scripts in the server which will accept parametres (POST data) and do operations based on the arguments that are supplied to it.
One way do to it would be through FTP.
You are basicallly describing WebDAV, which was created so that write-methods like those found in ftp could be done over HTTP.
I imagine it would be tricky to make a non-http file manager with PHP that was save and reliable.
There are several libraries for adding making WebDAV feasible in PHP, not that are core or standard extensions yet, though.
yes, this is either possible through php’s ftp functions or the native file system functions.
i wrote one myself (myftphp <-- advertisment :D)
using the native filesystem functions there are always restrictions on permission management, but for managing files in a public directory it’s perfect
See http://rosefinch.sf.net
A open source php file manager.
There is a fantastic remote filesystem manager available.
Just have a look at Flysystem.
It requires PHP 5.4 or higher.