Solved

Ftp question.

Posted on 2006-11-20
15
222 Views
Last Modified: 2011-09-20
I need a batch script to upload a file to a specific folder on a server.  The file name would be passed in a parameter.  I also have to login to this ftp server to upload.
0
Comment
Question by:casit
  • 8
  • 7
15 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 17980351
you can script ftp commands...

open yourftpserver
user
yourusername
yourpassword
bin
cd thefoldername
put thefilename

save this file as myscript.scr

then run it with

ftp -s:myscript.scr

you can reference: http://support.microsoft.com/?id=96269
for more info
0
 

Author Comment

by:casit
ID: 17980552
how do I use a variable in the upload file parameter.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980652
Has a lot to do with how you're setting the variable.
For instance, if you were setting it externally, in a batch file, something like this may work:

set thefilename=c:\myfolder\myfile.exe
ftp -s:myscript.scr %thefilename%

however, the myscript.scr would have to be adjusted so that it would 'put' that first parameter:

put thefilename
would become
put %1


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

 

Author Comment

by:casit
ID: 17981034
Now I'm getting the following.
ftp> mput %1
%1:File not found
ftp> close
221 Goodbye
ftp> quit
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17981098
Can you show me what your batch file looks like?
Offhand I suspect it's an issue with long file names or something...
0
 

Author Comment

by:casit
ID: 17981441
Well I changed my script somehwat so it now looks like this
[code]
Set ftpFile=%1

echo open cmuench.ath.cx >> ftp.scr
echo username >> ftp.scr
echo password >> ftp.scr
echo bin >> ftp.scr
echo cd test >> ftp.scr
echo mput %ftpFile% >> ftp.scr
echo close >> ftp.scr
echo quit >> ftp.scr
ftp -i -s:ftp.scr cmuench.ath.cx
exit
[/code]

Here is the output of ftp.scr
[output]
open cmuench.ath.cx
username
password
bin
cd test
mput -i
close
quit
[/output]

So my problem is when I commenout out the ftp command in the bat script in the output file is list mput filenamepassedtoit
No it doesn't
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17981706
ftp -i -s:ftp.scr cmuench.ath.cx
what is this?
it should be the absolute path to the file you want to send...

ftp -i -s:ftp.scr c:\myfolder\myfile.exe
0
 

Author Comment

by:casit
ID: 17981778
But the file I want to send I want to be a parameter when I call the batch script
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17982110
Okay - note I removed the double >> at the beginning to start a new file...I also added quotes around %ftpFile%

Set ftpFile=%1
echo open cmuench.ath.cx > ftp.scr
echo username >> ftp.scr
echo password >> ftp.scr
echo bin >> ftp.scr
echo cd test >> ftp.scr
echo mput "%ftpFile%" >> ftp.scr
echo close >> ftp.scr
echo quit >> ftp.scr
ftp -i -s:ftp.scr
exit
0
 

Author Comment

by:casit
ID: 17983005
The thing still goes in circles.
0
 

Author Comment

by:casit
ID: 17983014
And the log file still says mput -i
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17983220
Ah - I think maybe one problem may be the name of the script...try renaming ftp.scr to something else...I believe leaving ftp in the name can cause problems...
0
 

Author Comment

by:casit
ID: 17983998
Still no go
this is what it still outputs in the info.txt(I renamed ftp.scr to info.txt)


Here is my ftp.bat
[code]
Set ftpFile=%1
echo user >> info.txt
echo password >> info.txt
echo bin >> info.txt
echo cd test >> info.txt
echo mput "%ftpFile%" >> info.txt
echo close >> info.txt
echo quit >> info.txt
ftp -i -s:info.txt cmuench.ath.cx
exit
[/code]

[output]
chris
xxxxxx
bin
cd test
mput "-i"
[/output]
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17984202
We're missing something simple here, I just know it.

Alright, let's say your file is c:\pathtofile\subfolder\thefilename.exe

So, your run
MyFTPBatch.cmd c:\pathtofile\subfolder\thefilename.exe

correct?
and in your code, you should have
  open <ftp address>
between these two lines..

Set ftpFile=%1
echo user >> info.txt


Anyway - let's try it this way:

::start code copy
Set ftpFile=%1
Set scriptFile=c:\Test\info.scr
echo open cmuench.ath.cx > %scriptFile%
echo user >> %scriptFile%
echo yourusername >> %scriptFile%
echo yourpassword >> %scriptFile%
echo bin >> %scriptFile%
echo cd test >> %scriptFile%
echo Confirm the file name is correctly displayed: %ftpFile% and then
pause
echo put "%ftpFile%" >> %scriptFile%
echo bye >> %scriptFile%
ftp -s >> %scriptFile%
::you shouldn't need the -i parameter for what you're doing
::end code copy

Ah - but I see you are doing a -i multiple push...what are you passing as file specifications (you %1)?
Perhaps that's where the problem is..
0
 

Author Comment

by:casit
ID: 18039079
Nevermind I just wrote a perl script which was much easier.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

820 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