What's new

Batch Script to Upload a File to Your Server via FTP

jcgriff2

Site Administrator, Forum General Manager, BSOD Kernel Dump Expert
Staff member
Joined
Feb 19, 2012
Messages
17,461
Location
New Jersey Shore



BATCH SCRIPT TO UPLOAD A FILE TO YOUR SERVER​


The following batch script uploads a file to a client server via FTP.

Open up a Notepad; copy/paste the following into it:

Code:
@echo off

:: Obtain today's date in format YYYYMMDD
set x1=%date:~10,4%
set x2=%date:~4,2%
set x3=%date:~7,2%

:: The CSV file is presumed to be in your Documents directory 
set userdir=%userprofile%\documents

:: Build CSV file path + filename
set x=%userdir%\%x1%%x2%%x3%.csv

:: Echo the FTP commands to a text file - done so that ENV variables carry through
echo open  ftp.sysnative.com>%windir%\system32\ftpcmdtemp.txt
echo Server User Name>>%windir%\system32\ftpcmdtemp.txt
echo Server Password>>%windir%\system32\ftpcmdtemp.txt
echo binary>>%windir%\system32\ftpcmdtemp.txt
echo cd Enter server directory path - including "public_html" if Linux>>%windir%\system32\ftpcmdtemp.txt
echo put %x%>>%windir%\system32\ftpcmdtemp.txt
echo quit>>%windir%\system32\ftpcmdtemp.txt
  
:: FTP Execution Commands
ftp -s:%windir%\system32\ftpcmdtemp.txt %x%
Save it in \windows\system32; filename = FTPup.bat

Change the items in RED to your personal info.

To execute the newly saved FTPup.bat - enter the batch name into an ADMIN CMD prompt screen or go into Windows Explorer, RIGHT-click on FTPup.bat; select "Run as Administrator"

This particular batch script was written for an OP at TSF Forums.

For more information like the input file's name, please see my TSF post - batch script to upload csv to website mysql - Tech Support Forum

Any questions, modifications or other assistance, please post in this thread and I will try my best to answer them.

Regards. . .

jcgriff2

EDIT: Make sure the password has no special chars in it - batch thinks they are something else. Letters + numbers only.

For example - if you have an ampersand (&) in the password, a batch script sees it and expects a new command to follow. Many of the symbols above the number keys have a special meaning in batch.
 
Last edited:
Top