FTP Upload and FTP Download with VBScript

While Googling around the other day I noticed that lots of people are searching for a way to FTP files with VBScript. After looking for a while at the solutions to do this, it was clear that no real easy, free way of FTP uploading and downloading files was currently available. There are downloadable components that would present a programmable API. But these are costly, and you’d have to install them. So seeing the need I decided to whip up a couple of functions that would preform some basic uploading and downloading.

Pretty straight forward, you have to supply the credentials to connect to the machine, the IP address or DNS name for the machine and then the source and destination locations. Example of syntax:

When using the download function, if you don’t specify a location it will default to the working directory of the script. If for some reason there is a problem transferring the file the functions will return the error message. If they are successful, they will return “true”.

Update: I just made some corrections to this per the suggestions of some emails and comments I received. I retested this script, since it’s been quite some time since I’ve had the chance to use it, and it’s working like a charm. Please continue to report any issues you might have and thank you for your feedback.

 

15 thoughts on “FTP Upload and FTP Download with VBScript

  1. Thank you very much for taking the time to “whip” this up. I have been trying to use it in an application but have hit a problem and research would seem to show that there is no solution using the Windows built-in http://ftp.exe.

    The issue is that I need to use passive mode and, even though you could add ‘quote pasv’ to the command script, http://ftp.exe does not support passive mode.

    Thank you very much for the trouble but this is not a workable solution for using passive mode.

    Regards

    • I have used WinSCP in the past as a replacement for the limited functionality of the built in ftp client. You might see if that will work for your purposes.

  2. Don’t know what happened there. There shouldn’t be http:// in front of the “ftp.exe” as I was referring to the command.

  3. Thank you so much, saved me heaps of time and worked straight away.

    Usage for calling UploadFTP is:
    Wscript.Echo FTPDownload(“192.168.1.1”, “domain\user”, “password”, “C:\file.txt”, “\remote_dir\”)

  4. Oops my last comment was a bit premature… There’s an issue in the script when input file contains spaces e.g. “C:\Some Folder\file.txt”.

    The following statement returns false-
    oFTPScriptFSO.FileExists(sLocalFile)
    And therefore the function exits with value “Error: File Not Found.”

    The reason seems that it doesn’t like the string to have quotation marks in it. The quotation marks were added previously by the section commented –
    ‘Here we willcheck the path, if it contains
    ‘spaces then we need to add quotes to ensure
    ‘it parses correctly.

    So I’ve moved this section to after the path checks and everything seems to work fine.

    The path checks look like this now:
    ‘———-Path Checks———
    ‘Check to ensure that a remote path was
    ‘passed. If it’s blank then pass a “\”

    ‘Check the local path and file to ensure
    ‘that either the a file that exists was
    ‘passed or a wildcard was passed.

    ‘Here we willcheck the path, if it contains
    ‘spaces then we need to add quotes to ensure
    ‘it parses correctly.

    ‘——–END Path Checks———

  5. okay this script is the first uploaded script worked fine for me the problem its just upload the file name and show unknown error

    any idea about how to fix this

    Thnx

  6. Hi
    Your script looks great and is exactly what I need.
    I’m made a test ftp login and site and I’m calling the script like this:

    Wscript.Echo FTPUpload(“test.veylau.be”, “pptuser”, “***”, “\\192.168.100.8\Uurroosters\LokaalplanningKW\uitvoer\170907-vm-SO.mp4”, “\public_html”)

    Somehow it will not work, and the script blocks.
    Is is possible that the file size has something to do with it? (5mb?)
    Or do I call the function the wrong way?

    Thanks in advance for your amazing script!

  7. Hello, thank you for the code. Can you help add compress/zip logic before you upload the file? Are there free ways of compressing?

    Thanks
    Kalyan

Leave a Comment