Solved

Ftp question.

Posted on 2006-11-20
15
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes

734 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