Home: Perl Programming Help: Beginner:
Copy file from ftp directory after successful upload

New User

Aug 22, 2013, 11:41 AM

Views: 2730
Copy file from ftp directory after successful upload

Hi Guys,

I would like to create a perl script that will copy a file from my ftp directory to a different directory once it has successfully uploaded to my server. I want to verify that it was successfully uploaded by looking at the /var/log/xferlog and then if I can parse out a successful message for the given filename it would move it away from the directory immediately. I would have this run in a cron job and need it to be completely automated. For example if 5 files were uploaded they would be instantly moved out the directory as soon as a "successful transfer" messaged was received for it in /var/log/xferlog. Any help will greatly be appreciated.

Veteran / Moderator

Aug 22, 2013, 11:34 PM

Views: 2721
Re: [tbalz] Copy file from ftp directory after successful upload

Hmm, if you want to move a file as soon as it has beed loaded successfully, then a cron might not be the best idea. Can't you trigger the copy within the program that runs the FTP transfer?

Veteran / Moderator

Aug 23, 2013, 6:38 AM

Views: 2710
Re: [tbalz] Copy file from ftp directory after successful upload

Are the ftp uploads being done as a get or as a put i.e., is the upload initiated by a process on this server or from another server?

A common approach for this task is to have your script poll the upload dir for new files. If found, it will then poll every X seconds the file size of each file to see if it's growing. The upload is compete once the size stops growing, but that doesn't mean that it was successful. This is the point where you parse /var/log/xferlog to find that answer and then move or delete the file based on that status.

Do you have a test script that you're developing? If so, you should post it and provide detailed info on how it failing to accomplish the task and include any/all errors and warnings it produces.