Link to home
Start Free TrialLog in
Avatar of Shawn Janes
Shawn JanesFlag for United States of America

asked on

Automated FTP Upload using DOS?


I would like to create a .bat file I could call with Windows Scheduled tasks to automatically upload a file to my web server then delete the local files once they are uploaded.

So basically I would put the files I want uploaded in a directory on my local C: drive and nightly the files would upload to a folder on my ftp server. The file names will always remain the same and the directories in both locations would remain the same. Once the files have successfully uploaded I would then like the local files on my C: drive to be deleted.

There is a catch though, there are two files in the directory and those two files would need to be uploaded to different directories on the server.

A couple of things that would be nice is:

A) If the directory is empty no upload would take place
B) An automated email would fire off with the upload results
C) If I were at the computer a progress indicator would show me how much has been uploaded so far

Now I don't know how much if any of this is possible - it doesn't have to be over complicated, if VBScript is easier or is what I need, I am certainly not married to DOS.

Hopefully this is kind of clear. :-)

Avatar of JimFive
Flag of United States of America image

The dos ftp.exe can accept a script of commands and then called like:

ftp.exe -i -s:C:\MyDir\Myscript.ftp

In the Myscript.ftp you will need commands like:
lcd C:\MyDir
cd \destination1
put file1.txt
cd \destination2
put file2.txt
Avatar of sirbounty
scripting an ftp upload should be simple enough using dos.

@echo off
ftp -i -s c:\folder\upload.scr
del c:\folder\*.*

where upload.scr contains.

put FILE1
put FILE2
Avatar of Shawn Janes


Let me be a little more clear...

I have one folder on the local directory with two files in it. One file needs to go into one destination on the FTP server and another file needs to go into another destination on the FTP server. If it is easier to run two separate scripts to accomplish this then that's not a problem.

I would also like the file to delete from the local directory once it successfully uploads.

It looks like sirbounty has both files going to the same that correct?

The following VBScript file creates a file with FTP commands and then executes them. All you would need to do to this would be to change the username, password,  FTP site and file location for backup.

A progressbar is not possible in VBScript or with 'DOS'. E-mails are possible, yet I personally have not done much work using this, I have a friend who has told me to show you this website:

If you have any questions please ask.
'VBScript: FTPBackup.vbs
'Purpose: Backs up file(s) to an FTP
'Author: Ryan Kempt
'Date: January 25th, 2008
'Sets up our file system object which allows us to create and write to our temporary file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set tmpFile = FSO.CreateTextFile("C:\FTPInfo.tmp", True)
'Write execution plan for FTP
tmpFile.WriteLine("open")   'Hostname
tmpFile.WriteLine("MyUsername")                   'Username
tmpFile.WriteLine("MyPassword")                   'Password
tmpFile.WriteLine("binary")                       'Binary
tmpFile.WriteLine("put " & Chr(34) & "C:\" & Chr(34))
tmpFile.WriteLine("quit")                         'Quits
Set tmpFile = Nothing
Set FSO = Nothing
'Runs our temporary file which contains the preceeding FTP commands
Set objShell = CreateObject("WScript.Shell")
objShell.Run "ftp.exe -s:backup.tmp"
Set objShell = Nothing

Open in new window

Then you need two 'sections'
Though I've not ever done it, it should be easy enough with:

put FILE1
open SERVER2
put FILE2

No way that I know of to compare that the file was successful before deleting can list the files, but that won't be a true comparison...
Avatar of Ryan_Kempt
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Ryan. I do have one question:

If the file already exists on the server will this VBScript account for that? I wouldn't want it to fail if the file already exists since it will be overwriting itself whenever it does upload.

I'll take a look at the link from your friend in the meantime.

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the file already exists, it will overwrite it.
I split the points because I used some of each of your suggestions. I appreciate the promptness and details you provided with your solutions. Thank you - everything works beautifully.