Wednesday, August 29, 2012

Semi-Automatic & Automatic FTP Uploads and Downloads

Ever wonder how you can upload and/or download files from an FTP site automatically?  Well, I did recently.  So I tried to figure it out...

I had no luck with the FTP client program FileZilla, which is a good program and was already installed on my computer, but I did not see a solution for automation.  Nor could I find one on their support site and other forums.

Core FTP Pro FTP client has a built-in function that will enable you to schedule file transfers.  Yay, but the Pro version is not free, so I did not go there.  However, the free version, CoreFTP LE, has command line functionality.  In other words, you can create a batch file (.bat) to do the automation for you.  Once I discovered this, I stopped looking for other FTP clients or solutions.

If you have never worked with a .bat file, it is just a text file with commands and file names in it.  To create a .bat file, just create a .txt file with Notepad (Windows) and rename the file extension to .bat.  Use Notepad to open the .bat and do your editing.  If you are a Mac user, I'm sure there is an equivalent solution, but I do not know what it is.

Two example commands for uploading and downloading with CoreFTP LE are listed below...

Standard upload of a file with a site profile named 'mysite' into a remote directory /upload/:
"c:\program files\coreftp\coreftp.exe" -s -O -site mysite   -u c:\path\file.dat   -p /upload/

Download all text files from a remote directory /downloads/
"c:\program files\coreftp\coreftp.exe" -s -O    -site mysite   -d /downloads/*.txt   -p c:\windows\desktop\   

Copy & paste one of these examples into your .bat file and change the site name, file name and path accordingly...

Instead of testing this on your large CAD or BIM files right away, I would use a small PDF or something to start testing with.  Otherwise you may be waiting a long time before it finishes or terminates unsuccessfully.  Then after that works, change the file name in the command text to what you really want to upload/download.

For more CoreFTP code examples go to...
http://www.coreftp.com/docs/web1/Command_Line_FTP.htm

I like to put a pause statement at the end of my bat files.  This keeps the command window up after it finishes and it will let you see if it executed properly or not (you get prompted to Press any key to continue...).  I also like to add an ECHO or REM statement at the front to help describe what is going on. 



When your done editing, just double click on your .bat file to see if it works.  If it doesn't, check and edit your code and try again.

See link below to see how to use REM, ECHO any many more commands...
http://commandwindows.com/index.html

To have Windows run your batch files automatically when you want them to run, you can use Task Scheduler in XP or Windows 7 . 

However, for slow activity projects, I prefer the semi-automatic option of just double clicking my bat file whenever I want to do an upload.  Otherwise, you give the impression that there are real updates going on, when actually it is just a mindless upload and may confuse your recipients.


2 comments:

  1. You may also want to consider FtpScripter in one of your next posts. Thank you. :)

    ReplyDelete
  2. hi,i use

    Standard upload of a file with a site profile named 'mysite' into a remote directory /upload/:
    "c:\program files\coreftp\coreftp.exe" -s -O -site mysite -u c:\path\file.dat -p /upload/

    for autouploads, however how do i avoid reuploaded file ?

    ReplyDelete