windows: Command-line FTP help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

throdne

Thread Starter
Joined
May 14, 2006
Messages
128
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
 
Joined
Aug 7, 2007
Messages
9,028
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.

Code:
@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
 
Joined
Jun 5, 2009
Messages
14
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.

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

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

Code:
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Staff online

Top