Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP Upload Question - Spending Way Too Much Time

Status
Not open for further replies.

mickeyj2

Programmer
Jun 7, 2007
79
US
Hi,

Its been a while since I've done straight FTP batch. I'm VERY embarassed to have to ask this question.

I'm writing a batch file. The first part of the batch pulls some files down to my local machine. That part works great.

Now, I'm trying to add (to the latter half of my batch program), an FTP script that FTPs these files to my website.

Here's what I have. Consider the information inside the {} to be implied.


ftp {IP address here} /user:{username} /password:{password}
cd intranet.company.com
ls
close
bye


First off, I can't login without having the CMD shell prompt me for my username and password. I have confirmed all of the information is accurate. The whole point of the batch is so I don't have to supply anything extraneous.

Also, I have tried all of the following in my batch, and I still get prompted

ftp {IP address}
{username}
{password}
cd intranet.company.com
ls
close
bye

And nothing seems to work.

Any help to allow straight logging in. I'm thinking I might have to specify a port, etc.

Also, if I do successfully login, then I want to upload an entire folder (along with its sub-directories) to my FTP'd directory. I've tried mput, but it only moves the files.

Is there a straight statement for FTP that will tell me to "move not only my files, but also the sub-directories"?

Thanks in advance for any help you can provide.

mickeyj2
 
Hi, mickeyj2

Here is what I do to log in etc:

ftp.bat contains:

ftp -s:ftp.txt {ftp server name or ip address}

ftp.txt contains the commands you would manually enter into the ftp window as you get prompted, i.e.:

{username}
{password}
cd {directory path}
put {path and filename}
quit

or whatever is appropriate.

I don't know of any ftp command which copies subdirs, but I am not an expert. MPUT will allow you to put multiple files if GLOB is on you can use wildcards.

I will check an offline command reference I have somewhere and if I find anything I will post back.

Jock
 
mickeyj2,
this will get you on your way -
Code:
@echo off
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set weekday=%%a& set day=%%b& set month=%%c& set year=%%d)
cd c:\batch scripts\test ::local folder
@echo user ::username ::password>putlog.txt  ::replace ::user ::password with correct
@echo binary>>putlog.txt
@echo mkdir /%year%%month%%day%>>putlog.txt
@echo cd /%year%%month%%day%>>putlog.txt
::@echo put ::your file name here >>putlog.txt  ::replace ::your...with correct
::@echo put ::another file name here >>putlog.txt ::replace ::another...with correct
@echo off
dir /b *.txt >filelist.txt
...
for /f %%i in (filelist.txt) do @echo put %%i>>putlog.txt
@echo bye >>putlog.txt
::ftp -n -d -s:putlog.txt 0.0.0.0 :: replace 0's with correct ip
please note that you are putting an unencrypted user name and password that has the ability to at least add files to your server into a file that anyone can open & read.
i do not remember if i ever tested this script but it should give you then general concept.
regards,
longhair
give a man fire & he'll be warm until he runs out of fuel
set a man on fire & he'll be warm for the rest of his life

(^o^)
 
Hi Jock and longhair,

This worked out for me just fine. After I moved the FTP batch to another file and had my DOS batch call it, then it worked out.

Thanks for your help.
mickeyj2
 
Hi,

I had one more question. I've scheduled a daily run of my batch file from within Windows XP. Is there any way to "dump" the run of that batch file to a log file that I can review, so I'll know exactly how it ran?

Thanks for your help.

mickeyj2
 
Hi Mickeyj2

Just add "> ftplog.txt" to the end of the ftp command in the .bat file. That will create/overwrite ftplog.txt and it will contain all the output from the ftp session.

Jock
 
Hi Jock,

Sorry its taken me so long to answer - my computer crashed.
Thanks for your help on this. It worked like a charm. I hadn't realized how much I'd forgotten about FTP.


Thanks for all of your help.

mickeyj2
 
Hi, Mickeyj2

Most welcome. Us legacy geeks always appreciate a chance to be relevant (grin).

Jock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top