1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

windows: Command-line FTP help

Discussion in 'DOS/Other' started by throdne, Apr 1, 2010.

Thread Status:
Not open for further replies.
  1. throdne

    throdne Thread Starter

    May 14, 2006

    I'm trying to run a batch file that runs a FTP script.

    this is the step I would like it to take.

    Run send.bat
    mkdir named "%computername%"
    CD into %computername%
    put (copy everything from a directory to ftp server)

    but the problem that I am having is that the mkdir makes a file called %computername% but i really want it to be the computer's real name, like ThrodnePC or Server or ThrodneLT. how would i go about doing this in a ftp script.

    this is what i have so far.

    ::FTP INFO
    ftp -s:ftp.scr


    open "domain"
    mkdir %computername%

    Thanks to anyone that replies to my post.
  2. TheOutcaste


    Aug 7, 2007
    For this you would need to have the batch file create the ftp script on the fly, so it can insert the current list of files and expand the variables.

    Here's my Generic FTP uploader. Just modify the first 5 Set statements as needed.

    @Echo Off
    :: _FTPServer   The ip address or url for the FTP Server
    :: _Username    The User name to log into the FTP Server
    :: _Password    The passsword for the FTP Account. This is readable by anyone
    :: _FTPFolder   The folder to use on the FTP Server
    :: _LCD         The local directory on the PC that you want to upload
    :: _FTPScript   The path\name of a temp file to use for the FTP Script. Default is
    ::              FTPScript.txt in the current user's temp folder. It is created
    ::              on the fly, and deleted when finished unless there is an error.
    [COLOR=Red][B]:: Edit these lines as needed for your server[/B][/COLOR]
    Set _FTPServer=upload.comcast.net
    Set _Username=username
    Set _Password=password
    Set _FTPFolder=%Computername%
    Set _LCD=C:\My Files
    :: Create FTP Script. Login, change local directory, make remote directory
    :: Change to that directory, then switch mode to Binary
    Set _FTPScript=%Temp%\FTPScript.txt
    (Echo.open %_FTPServer%
    Echo.lcd "%_LCD%"
    Echo.mkdir "%_FTPFolder%"
    Echo.cd "%_FTPFolder%"
    :: Now need to create a list of files to upload. /A-D switch excludes
    :: folders buts gets hidden and system files 
    For /F "Tokens=* Delims=" %%I In ('Dir /A-D /B "%_LCD%\*.*"') Do Echo.put "%%I">>"%_FTPScript%"
    :: now add quit command
    >>"%_FTPScript%" Echo.quit
    :: Script is created, now run the script
    :: For testing, uncomment the next two lines. THis will open the script
    :: In Notepad for review.
    :: Notepad "%_FTPScript%"
    :: Goto :EOF
    Echo Uploading files, please wait
    Ftp -v -s:"%_FTPScript%"
    If Not ERRORLEVEL 1 Goto _Cleanup
    Echo.There was an FTP Error of %ERRORLEVEL%
    Echo.The script file will not be deleted.
    Echo. Location of script file is "%_FTPScript%"
    Goto :EOF
    Del /F /Q "%_FTPScript%"
    Goto :EOF
  3. PatrickMc


    Jun 5, 2009
    I think you already have a good answer posted already.

    Some additional thoughts.

    - What if you use %%computername%% in the FTP script ?
    - For creating FTP script (as TheOutcaste suggested), take a look at this script.


    Look at the command.

    lf -n "*" $localdir ($ftype=="f") > $localfilelist

    By customizing this command, you can precisely select the files you want to upload. For example,

    lf -n "*" $localdir ($ftype=="f") AND ($fmtime > addtime(diff("-24000000")) ) > $localfilelist

    It will upload only the files modified in last 24 hours.

    I have been using similar modifications of that script for various purposes. Seems to work nice.
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/914121

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice