# windows: Command-line FTP help



## throdne (May 14, 2006)

Hello,

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
ftp 
login
mkdir named "%computername%"
CD into %computername%
put (copy everything from a directory to ftp server)
quit.

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. 

send.bat
---------------------------
::FTP INFO
ftp -s:ftp.scr	

----------------------------


ftp.scr
----------------------------
open "domain"
username
password
mkdir %computername%



Thanks to anyone that replies to my post. 
Throdne


----------



## TheOutcaste (Aug 8, 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
Setlocal
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: _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.%_Username%
Echo.%_Password%
Echo.lcd "%_LCD%"
Echo.mkdir "%_FTPFolder%"
Echo.cd "%_FTPFolder%"
Echo.binary
)>"%_FTPScript%" 
:: 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
:_Cleanup
Del /F /Q "%_FTPScript%"
Goto :EOF
```


----------



## 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.

http://www.biterscripting.com/helppages/SS_FTPUpload.html

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.


----------

