bergertime
asked on
vb.net move files from one folder to another on a schedule
I have a folder on my FTP server. I need to take the files in it and move them to a different folder every 10 minutes. Looking for either ideas on doing this using vb.net or a program already out there?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in case you need a free library, consider these:
http://ftps.codeplex.com/http://ftps.codeplex.com/
http://www.enterprisedt.co m/products /edtftpnet /overview. html
I have never used Robo-FTP but if it does the job $150 for a licence is not a rip-off :)
http://ftps.codeplex.com/http://ftps.codeplex.com/
http://www.enterprisedt.co
I have never used Robo-FTP but if it does the job $150 for a licence is not a rip-off :)
ASKER
AlexPace, ok RoboFTP is cool, one question, can I rename the files as they are being moved? Say the file is MyFTPDocument.edi and I want it to be data1.edi, data2.edi, data3.edi.......etc. Otherwise for 150 this will be used a lot. Thanks
in FTP there's no "move" per say. Moving a file is actually renaming it :-) of course you rename the whole path including file names, hence both the file name and the folder can be changed.
Yes you could use a counter to give names like data1.edi, data2.edi, data3.edi and just increment the counter in the loop... but if you could get away with also adding a date then you'll also solve the problem of overwriting a file with another file that has the same name.
For example, suppose the computer reboots and it restarts script counter at 1 but you already have a saved file named data1.edi so that file gets overwritten. You could use the %datetime variable along with a number to guarantee each file name was unique like this:
Another idea that does not include a date might be to use a text file file to keep the last used number persistent through reboots ... the READFILE and WRITEFILE commands would help you do that. You could do the same thing with a database table and commands like DBQUERY and DBGETRESULTS but that is overengineering it a bit I think I would stick with the text file if I had to have persistent numbering.
For example, suppose the computer reboots and it restarts script counter at 1 but you already have a saved file named data1.edi so that file gets overwritten. You could use the %datetime variable along with a number to guarantee each file name was unique like this:
SETNUM counter = 00000
:start
FTPLOGON "myftp.server.com" /user="UserID" /pw="secret"
FTPCD "/source"
:find_file_to_move
FTPGETFILE "*"
IFERROR GOTO done
INC counter ;; increment the counter variable
SET new_name = "/destination/folder/data" + counter + %datetime + ".edi"
FTPRENAME %sitefile new_name ;; rename file's path to move it on an FTP site
IFERROR GOTO done ;; this is a failsafe... it shouldn't happen
GOTO find_file_to_move
:done
FTPLOGOFF ;; harmless error if not connected
PAUSE /for=600 ;; Ten mins is 600 seconds ...
GOTO start
Another idea that does not include a date might be to use a text file file to keep the last used number persistent through reboots ... the READFILE and WRITEFILE commands would help you do that. You could do the same thing with a database table and commands like DBQUERY and DBGETRESULTS but that is overengineering it a bit I think I would stick with the text file if I had to have persistent numbering.
ASKER
Alex, good. I have to keep the name under 10 charactors, I had tried to use the date just the minutes and seconds, but it's no big deal, once they get renamed, they get consumed and deleted so reboots are no big deal. But it's the strangest thing. I have 10 test samples in my folder. First pass through it gets a few, next pass through it gets a few more.....always the same files until they all get renamed. I think I can get it from here. Thank you so much. Just wondering if you had seen it missing some of them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dude, you rock.
ASKER
Thanks for making something boring and tedious actually kind of fun.
Thanks for the kind words!
Open in new window
The Robo-FTP license will set you back $150 but, if this is for work purposes, your boss will probably spend at least that on one hour of your programming time so maybe it would be worth it considering that it is supported commercial software and might be useful for automating other things in your office.