If FTP harvest is to be used for uploading more than 2 or 3 files at a time, by end users, the interface needs to be a little simpler to use.

I am suggesting users need to be able to upload an entire folder of files, the folder itself being the token, instead of requiring users to re-name each file they want to update. This will make FTP uploading more than a single file at a time far more accessable to the average user.

This could be enabled as a switch, or just a default behavior.

Comments

a_c_m’s picture

Made some good progress on this today, should have a patch tomorrow for review.

arthurf’s picture

Awesome, looking forward to seeing it

a_c_m’s picture

Version: 6.x-1.0-beta2 » 6.x-1.0-beta1
Status: Active » Needs review
StatusFileSize
new14.91 KB

You might want to look at this closely, as the patch really is against BETA-1, so i think it take a backward step on a few things, sorry about that :(

I added 3 options to the config,

1) Harvest from token folders
2) Delete token folders after harvest
3) Delete any non token folders

The code to make this work is in inserted into a few places

1) media_mover_ftp_connect() : It now creates $connection['ftp_folders'] (if the correct config is in place) with an array for each folder in the base dir containing a ftp_rawlist of the folder.
2) media_mover_ftp_harvest() : it now loops though these extra folders in the same way as it did for the base folder
3) media_mover_ftp_token_extract() : it now checks for a folder token if it doesn't find a file token
4) mm_ftp_parse_file() : a minor modification to allow returns of directory information

I also added a helper function ftp_rmdirr() which was kindly donated by Aidan Lister (http://aidanlister.com/repos/v/function.ftp_rmdirr.php) to allow ftp directories to be deleted recursively (ftp_rmdir() requires the folder be empty). He is going to re-write it shortly to allow it to work on servers that dont support the LIST -R command.

What do you think?

a_c_m’s picture

there are some extra dsm()'s in there that i forgot to take out. will roll another patch if you want.

arthurf’s picture

I'll look through this in the next few days. Have you looked at http://drupal.org/node/442078 ? I think that issue is also going to impact this as well- not that you have to solve it, but it is something that will need to be addressed with directories and individual files.

We may also want to add a "type" col to the token table so that we can have more complex handling in the future.

Also, any ideas about the token generation- my approach is not the best I think

a_c_m’s picture

http://drupal.org/node/442078 is a good point, perhaps a pre-download check per file might be in order, or a wrapper for ftp_rawlist which does the double request check and only returns valid results.

Token gen yes could do with some work, i think the token is there for 2 reasons, to uniquely identify the user and to be able to change, so perhaps a simple 2 part key, part 1 based on the uid and part 2 is a random much shorter string. Currently there is no collision detection - right?

a_c_m’s picture

StatusFileSize
new15.92 KB

Re-rolled minus the dsm() statements with a new function called _media_mover_ftp_completedlist() which solves the http://drupal.org/node/442078 issue, with an extra flag to allow for "strict" compliance. This means when using folders, it wont return ANY results if anything in that folder is still uploading - this avoids problems later when the system deletes folders its harvested from.

I also took a simple shot at improving the token generation, its now adds the UID to a rand() (instead of time) for the seed, the generation is done inside a do-while loop to insure the key is unique then the old token is removed (so in theory it can be re-used). The issues we have still would be on VERY large sites that do-while loop could go on for some time, hitting a lot of duplicates, but thats more a function of the char limit. I'm sure a cryptographer or someone else might be able to take a better shot at this, but for me, it works.

arthurf’s picture

StatusFileSize
new8.24 KB

Hi-

Thanks for this patch- I think this is a strong push forward. A few points

1) can you use cvs diff -up >patchfile for creating patch files? It makes it easier to apply them
2) in the function media_mover_ftp_connect you are checking the full directory list of files- do we need to do this? Since we can already get a list of files, we know we can get a listing- so I think this is not necessary, but maybe I misunderstand.
3) I've applied the patch to 6-1x by hand- doubtless I've messed something up, or missed something- you'll want to backup your file before you apply it
4) I only applied the changes to media_mover_ftp.module so far- before I did the rest of it, I wanted to make sure that I'm on the right track
5) I changed a few things around to conform to the media mover style a bit more, but tried to keep your work in place. Please edit as you see fit :)

a_c_m’s picture

1) Will do!
2) In media_mover_ftp_connect the first rawlist is for the base dir say "/" in then also get rawlists for any of the folders inside "/" e.g. "/123456", this is so later, when we harvest were not getting more listings adhoc, seemed "media mover"-y to get it all in one batch like that.
3) Looks ok, will test later as we are putting live the work i've done on it so far right now, but I will update to the approved version once its ready.
4) Looks good, im in IRC if you want a more interactive conversation.
5) Will do :)

arthurf’s picture

I'm going to apply this to the dev branch in 6x as I have some additional work that depends on this- specifically naming directories after user names and pulling the author names from there.

arthurf’s picture

I've now gone through this quite a bit in order to improve recursive directory handling. I'm trying to cleanup the function call stack so things are more consistent and orderly. I need to cleanup the file handling on the harvest side which will take the new data model into account, but I think this is going to yield much better functionality and simpler code. Code has been committed to 6x

a_c_m’s picture

in that last commit - you have a "print 'here';" ;)

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/media_mover...

i will check it out when i get a free moment or 2. My alpha code has so far processed 4k uploaded files!! But I know your refactored code will probably be nicer.

2 things we've seen.

1) Recursive delete of folders is a pain, still for servers that dont allow recursive listing
2) Hidden files, starting with . which are sometimes generated by systems are not caught by my script so can also cause issues when trying to delete harvested folders.

Other than that, its been working really well.

arthurf’s picture

Sorry about the print, just trying to get code in.

I've done a big refactor in how the file listing is built for the actual harvest. In the $ftp_file array that is passed to the actual harvest functions, I've added 'token' if it is present on the file, and 'user_name' which it attempts to guess from the parent file. A 'user_name' is pulled out in the user extract function- along with the token. Parent directories can also contain tokens which will be used as well.

I've also changed the $file['harvest_file'] to use the file path on the FTP server- this can now be used for uniqueness checking (have not implemented yet).

The major problem that I see is that the directory listing build takes a *long* time with a large directory structure. I'm not sure how to improve the performance there. Perhaps there are some bad code decisions that I made... not sure.