Solved

Monitor FTP Folder(s) and Download Files to Specific Local Folders

Posted on 2013-10-30
2
870 Views
Last Modified: 2013-11-21
Hey All -

I've got a project which I'm trying to script that I cannot get to work correctly.  I have a remote location which has a folder named "Complete" in which files are dumped to at random times.  Some files may go directly in the root and others into folders in the root.  Each of the files' names will be different and one of about 5 different of extensions

Remote Example:
- Complete/UbuntuLinux1.iso
- Complete/Mint1/LinuxMint.zip
- Complete/Windows/Windows7.rar

Currently, I log in a few times a day via FTP, select the files I want, download them to one of 5 local folders, then delete the rest of the crap.  What I'm trying to do is automate this
process.

I tried using SmartFTP to create schewdules, but couldn't find a way for it to monitor a remote FTP site for changes.

Below is what I would need it to do / rules:
- Monitor folder on remote FTP site (including it's child folders) for new files which end in 1 of 5 extensions (.zip, .rar, .iso, .img, & .bin)

- Examine the filename - if "linux" is anywhere in the filename, download to the local "Linux" Folder.  If "Windows", then download to the local "Windows" folder, and so on.

Local Example of same remote files:
- Linux\UbuntuLinux1.iso
- Linux\LinuxMint.zip
- Windows\Windows7.rar

Any ideas for applications or scripts that may help with this? Is it makes any difference, I can connect to the remote site using FTP, FTPS, HTTP, or HTTPS.

Last resort would be for it to monitor and download everything in a specific remote folder, then have a separate application sort it all out.  Any ideas on this would be helpful, too.

Thanks!
0
Comment
Question by:BzowK
2 Comments
 
LVL 16

Accepted Solution

by:
AlexPace earned 500 total points
ID: 39613106
You could do this with Robo-FTP running a script as a Windows service... change the download folders on those first two lines and then the logon information on the 5th line.
SET windows_folder = "c:\download\windows"
SET linux_folder = "c:\download\linux"

:connect
FTPLOGON "ftp.new.com" /user="UserID" /pw="secret"
FTPCD "Complete"
IFERROR GOTO long_sleep

:loop
FTPGETREWIND
FTPGETFILE "*" /incldirs 
IFERROR= $ERROR_NO_FILE_FOUND GOTO long_sleep 
IFERROR GOTO short_sleep
SETRIGHT extension = %sitefile 4
IFSTRCMPI extension ".zip" GOTO extension_OK
IFSTRCMPI extension ".rar" GOTO extension_OK
IFSTRCMPI extension ".iso" GOTO extension_OK
IFSTRCMPI extension ".img" GOTO extension_OK
IFSTRCMPI extension ".bin" GOTO extension_OK
; if we reach this line the extenions is no good
FTPDELETE %sitefile
GOTO loop

:extension_OK
IFSUBSTRI %sitefile "linux" GOTO download_linux
IFSUBSTRI %sitefile "windows" GOTO download_windows
; if we reach this line the filename lacks linux or windows
FTPDELETE %sitefile
GOTO loop

:download_linux
WORKINGDIR linux_folder /create 
RCVFILE %sitefile /delete
IFERROR GOTO short_sleep
GOTO loop

:download_windows
WORKINGDIR windows_folder /create 
RCVFILE %sitefile /delete
IFERROR GOTO short_sleep
GOTO loop

:short_sleep
PAUSE /for=3  
FTPLOGOFF
GOTO connect 

:long_sleep
PAUSE /for=300  ; 300 seconds is 5 minutes
FTPLOGOFF
GOTO connect

Open in new window

Note: I havn't tested this so it is sure to have a couple of bugs.

Edit: to use FTPS append the following to the FTPLOGON line:
  /servertype=FTPS /trust=all
0
 

Author Closing Comment

by:BzowK
ID: 39666282
Was able to edit and add a few lines and it worked - Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now