1. #1
    jcgriff2's Avatar
    Join Date
    Feb 2012
    Location
    New Jersey Shore
    Posts
    14,787

    Batch Script to Upload a File to Your Server via FTP




    BATCH FILE 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 by jcgriff2; 07-07-2017 at 01:18 PM.

    BSOD Posting Instructions - Windows 10, 8.1, 8, 7 & Vista ` ` `Carrona Driver Reference Table (DRT)
    https://www.sysnative.com/
    Sysnative Hex-Decimal-UNIX Date Conversion

    Has Sysnative Forums helped you?
    Please consider donating to help support the forum.
    Thank You!

    Microsoft MVP 2009-2015


    • Ad Bot

      advertising
      Beep.

        
       

Similar Threads

  1. [PHP] Upload Script
    By Will Watts in forum Programming
    Replies: 4
    Last Post: 07-12-2013, 03:54 PM
  2. A Simple Batch Script Explained
    By jcgriff2 in forum Programming
    Replies: 5
    Last Post: 03-18-2013, 07:08 AM
  3. Pass Generator Batch script - Created by Ace
    By AceInfinity in forum Programming
    Replies: 0
    Last Post: 10-01-2012, 01:24 AM
  4. WMI batch script to obtain literal and numeric day of week
    By jcgriff2 in forum Windows Tips & Tricks
    Replies: 1
    Last Post: 07-10-2012, 11:28 PM

Log in

Log in