james28909 has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a method to backup files (they will be small files) and the server in which I am using supports the XMD5 command, which requests and returns the md5 hash of any selected file. What I am trying to figure out how I can use this XMD5 feature with Net::FTP. Does anyone know how I could accomplish a task of this nature?

here is the link for reference

maybe something like my $remote_md5 = $ftp->xmd5($filename); this would be a nice feature to add to Net::FTP

Replies are listed 'Best First'.
Re: XMD5 and Net::FTP
by dasgar (Priest) on Oct 13, 2014 at 21:18 UTC

    Have you checked out the Methods for the adventurous section of Net::FTP's documentation?

    From that section, it describes the quot() method as: "Send a command, that Net::FTP does not directly support, to the remote server and wait for a response." This sounds like what you're needing to do. Might also want to pay attention to warning noted in the documentation for this method.

      awesome, and no i did not see that section. looks promising tho, and would work great to only upload if files md5 has changed. this would work great for smaller files, but on bigger files there would need to be some other way like rsync. but i am not to sure if that would work on an FTP server.

      just sent command XMD5 <filename> and it returned correct md5 so looks like this will work out great. i just need to get a list of directories and filenames and push that to an array, then i can do a foreach loop on each file and see if it exists on the server. if not then upload it. then after that i can set it up to add any new files or check md5 of existing files. and upload where appropriate. this will be awesome as a poor mans dropbox lol
Re: XMD5 and Net::FTP
by flexvault (Monsignor) on Oct 14, 2014 at 11:06 UTC

    james28909,

    I think you have your answer about using MD5 stamps, but you are adding a lot of CPU work to find out that a file has changed ( or not ) and you are not guaranteed that the MD5 will be different. A few years ago, I took 400K files and did MD5 of each file and then sorted the results. I found that many different files had the exact same MD5. MD5 is great for determining that 2 files are the same, but not necessarily that they are different. YMMV.

    To get the results I needed, I used the 'find' command with the '-newer' option to build my list of files to backup. Immediately after the 'find', I would 'touch' a file for getting my base target for the next 'find' cycle. Unfortunately, depending on long the 'find' took to execute, sometimes I would miss a file, and so I changed the file timestamp to exactly the same time that the 'find' started each cycle.

    Just giving you some thoughts before you finish your design. Also look at 'rsync' for some ideas. Good Luck!

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

      well actually i am having a bit of another problem in which i have never had to deal with to much. i am recursively traversing directories in "$ENV{USERPROFILE}\\Files_to_sync\\". or in other words i am scanning all directories and sub directories for files in this directory. but i am having problems only uploading the files in sub directories inwhich it is wanting to upload C:/Users/username/Files to sync/folder/another folder/file.txt for example. i just want it to upload folder/another folder/file.txt.

      i have setup a regex that strips the beginning of the path off to exactly what i need, but then i am having problems with file not found. is there a way to upload only what i am asking? or am i overlooking something simple. I can however upload single files from the "files to upload" folder, but i cannot upload empty subdirectories or sub directories with files ect ect.

      can you give me an idea of what i need to do? because it seems like cwd is going to do the exact same thing i am trying to do which is return the exact cwd, but then somehow i got to upload only files and directories and sub directories in "files to upload" folder.

      and thanks for the insight. i will def look into other methods as soon as i can understand this little predicament i am in. i have no problems building a fils/directories list and pushing it to an array, the problem comes in when i try to upload the regexed path/filename.

        james28909,

        I'm not that up on Windows. *nix is my bag, so if no one else answers you, just ask this specific question as a new topic. Please also include the OS and version. While Perl is everywhere, how it interacts with the operating system may be very different.

        And again, Good Luck!

        Regards...Ed

        "Well done is better than well said." - Benjamin Franklin