Check for File on Remote Server

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
macrunning
Pro Scripter
Posts: 68
Joined: Wed May 04, 2005 10:24 pm

Check for File on Remote Server

Post by macrunning » Wed May 04, 2005 10:27 pm

I was wondering if anyone new how to connect to a remote server and see if a file exists on the server and if so then download that file and if not end the script. Any help would be greatly appreciated. Thanks macrunning~!

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed May 04, 2005 10:57 pm

Here is a stripped down variation of code I use every week. This stripped down version has been edited, and is untested, so I may have made some errors here.

If no file was available, a destination filename would still exist, but size=0, so filesize is checked vs. filename. If filesize>0 then macro assumes file was downloaded and macro deletes original file on the source. You may not want to delete after download.

You will need to fill in the initial variables (Let> statements) to suit your situation. If no file is downloaded five attempts are made, 15 seconds apart. Count and time are user defined.

Code: Select all

//Macro to download files from FTP site
//User defined variables
Let>WorkDir=Drive:\DestinationPath
Let>FTPServer=ftp.servername.com
Let>FTPUser=username
Let>FTPPW=password
Let>ftpfilename=NameOfFileToGet

Let>GetCount=0
//GetMax is the maximum of attempts to do the FTP download.
Let>GetMax=5
//GetWait is the number of seconds to delay between FTP attempts.
Let>GetWait=15
CAPSOFF
Let>SK_DELAY=10
//============================================

//Open FTP file and download
Label>Start

//Move to working directory
Change Directory>%WorkDir%

Label>GetFTP
FTPGetFile>%FTPServer%,%FTPUser%,%FTPPW%,21,%ftpfilename%,%ftpfilename%I

Label>ConfirmDownload
Let>ftpfilesize=0
FileSize>%ftpfilename%,ftpfilesize
If>%ftpfilesize%>0,DeleteFtp

//Added loop to wait .5 min and try max of 5 times then quit
Let>GetCount=%GetCount%+1
Message>File %ftpfilename% not downloaded.%CRLF%%CRLF%Download attempts: %GetCount%.%CRLF%%CRLF%Will try again every %GetWait% seconds for a maximum of %GetMax% attempts.
Wait>%GetWait%
If>%GetCount%<%GetMax%,GetFTP
Message>File %ftpfilename% NOT downloaded!%CRLF%%CRLF%Download attempts: %GetCount%.%CRLF%%CRLF%FTP Download process has been stopped.%CRLF%Try again later.
Wait>10
Goto>End

Label>DeleteFtp
FTPDelFile>%FTPServer%,%FTPUser%,%FTPPW%,21,%ftpfilename%
Message>DOWNLOAD WAS SUCCESSFUL.

Label>End
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

macrunning
Pro Scripter
Posts: 68
Joined: Wed May 04, 2005 10:24 pm

Thanks

Post by macrunning » Wed May 04, 2005 11:14 pm

I will give it a shot. Thanks for the help and the quick reply.
Have a good day.

macrunning
Pro Scripter
Posts: 68
Joined: Wed May 04, 2005 10:24 pm

Quick questions

Post by macrunning » Wed May 04, 2005 11:23 pm

One quick questions. Is 'Let>WorkDir' the directory on my harddrive or the remote server?

macrunning
Pro Scripter
Posts: 68
Joined: Wed May 04, 2005 10:24 pm

Got it!

Post by macrunning » Wed May 04, 2005 11:39 pm

Nevermind. I figured it out. Thanks again for the help. You wouldn't happen to know if this program can resize images from say a larger dimension size down to a 320 x 240 size. I'm working on downloading the zip file from the server (which is full of image files), then processing the image files and automaticlly uploading them to a different server. If you have any ideas I would be forever thankful. Currently I'm manually processing all of them through photoshops actions process but this can still be cumbersome at time.
Till Later,
macrunning

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts