?
Solved

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

Posted on 2013-10-30
2
Medium Priority
?
924 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
AlexPace earned 2000 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

801 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