Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

FTP batch file problem

Posted on 2006-05-23
21
Medium Priority
?
642 Views
Last Modified: 2013-11-29
Hi,

I have put together what should be a straight forward ftp batch file as follows;

ftp -v 10.10.1.10
user
password
put c:\windows\afm.pl
quit

When ran, the batch file executes the ftp -v 10.10.1.10 part however when the username prompt displays, the second line and other commands do not execute.

Does anyone know if I am missing something?
0
Comment
Question by:nickmarshall
  • 8
  • 7
  • 6
21 Comments
 
LVL 5

Expert Comment

by:skaap2k
ID: 16741644
You should use the syntax ftp -s:<batchfilename>
now, your script itself should look like this:

connect 10.10.1.10
USER <username>
<password>
put c:\windows\afm.pl
quit

that should do it for you.

rgds,
Rob
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16742205
As skaap2k says but slightly different as far as I remember you actually need to leave out the user entry and put easiest is to put the IP on the command line, other way might work too, haven't tried.

ftp 10.10.1.10 -s %0
goto end
username
password
put c:\windows\afm.pl
quit
:end

Ideally I like putting the script file bit in a different file to the batch file containing the ftp command but it does work like this.

%0 refers back to the name of the batch file BTW.

Steve
0
 
LVL 5

Expert Comment

by:skaap2k
ID: 16742510
there are loads of different ways here is another that works for me now:

ftp -s:<Batchfile name>


Batchfile:

open <ip-address>
<username>
<password>
put c:\test.txt
quit

which is very similar to your first example but works and transfers the file

-Paul
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:nickmarshall
ID: 16742967
Thanks so far...

I need to put all of the commands within the batch file as I have a exe compiler program so that people cannot see the username and password

Also, I will be adding it to scheduled tasks.
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 16742977
When I run (some details changed) ;

ftp 10.10.1.10 -s %0
goto end
username
password
put c:\windows\afm.pl
quit
:end

It simply constantly comes up with the command prompt showing the first line continuously

0
 
LVL 5

Expert Comment

by:skaap2k
ID: 16742980
great :)
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 16743193
Any ideas why this happens?
0
 
LVL 5

Expert Comment

by:skaap2k
ID: 16743331
yes because it is not executing the data in the script file.

what you need is two things:

1. The script file .. for this example i will call it    ftpscript.scp   (you can call it anything)

so in ftpscript.scp are the following lines:
       
      open <ip-address>
     <username>
     <password>
      put c:\<file that you want transfered>
      quit


2. To execute the script file, type :   "ftp -s:ftpscript.scp"

you can put this command into a batch file and execute the batch file using your scheduler or the scheduler can just execute the command as i have written it up above. (dont forget to put the path to the script file into the command if it is being executed from somewhere else)


See if that works for you

-Paul

0
 
LVL 1

Author Comment

by:nickmarshall
ID: 16743740
Ok,

I have done the above however it still comes up with the first line executing continuously.

?? abit strange...

I also need to make sure that the scp file is not readable, which is why I purchased a batch file compiler
 

Please help
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16743773
I believe the other way works too though to be honest I would always try and use two files as also suggested but it does appear you are trying to do it all in one which is why I suggested that.  What is your batch file called btw, have seen it called ftp.bat before which confuses things of course?
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 16743783
Hi,

It is called ftp.bat

The scp file is called ftp.scp

How could this be done in one batch file... this is what I need so that I can compile to an exe.
0
 
LVL 5

Expert Comment

by:skaap2k
ID: 16743786
So, what have you done exactly?
0
 
LVL 5

Expert Comment

by:skaap2k
ID: 16743820
The problem is that you called the one FTP.bat .. this confuses the situation. rename ftp.bat to myftp.bat

-Paul
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 16743849
getting somewhere now, that executes fine however I still need the text part contained within the batch file.

how would I include the text part in the batch file?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16744170
Do what I suggested above and don,t call it ftp.bat as I suggested above as this causes the first line to keep running over and over as it runs itself,

I.e.

ftp ipaddress -s %0
goto end
username
password
put whatever
quit
:end

Steve
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 16746182
Right, having had a chance to check why this doesn't work... if you run the batch file with batch then %0 becomes batch if you run it with batch.bat it becomes batch.bat so... it doesn't pass the full path to FTP.  You can get around that with:

ftp -s:%~f0
goto end
open ipaddress
username
password
put /whatever
quit
:end

or depending upon how your compiler works it might have to write a temproary file out as follows:

@echo off
REM Set filename for temporary file in temp directory and delete any previous one.
set ftpfile=%temp%ftpscript.txt
if exist %ftpfile% del %ftpfile%

REM Write temporary FTP script to above file
REM Make sure no space between username and password and the redirection more than sign
echo open ipaddress> %ftpfile%
echo username>>%ftpfile%
echo password>>%ftpfile%
echo put /myfile>>%ftpfile%
echo quit >>%ftpfile%

REM Execute FTP using script then delete it
ftp -s:%ftpfile%
del %ftpfile%

Steve
0
 
LVL 5

Expert Comment

by:skaap2k
ID: 16749209
Nice one Steve - the first one didnt work for me, but the second one where it makes a temporary file works perfectly. I know i didnt ask the question ... but nice solution!

-Paul
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16749409
Thanks.  Hope it will compile OK into his EXE.

Steve
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 16749436
Excellent Steve...

It's working now... many thanks!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16749459
No problem, thanks for the grade and points
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 16749469
Hi Steve,

In some folders there are multiple data files, which appears to cause problems with the batch file

I have used the line;

echo mput c:\windows\audit\*.vap>>%ftpfile%

The batch file hangs..... and nothing is displayed.

Would you know a way around this.

Many thanks for your help! :-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question