Solved

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

Posted on 2013-10-30
2
879 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 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

19 Experts available now in Live!

Get 1:1 Help Now