Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ftp question.

Posted on 2006-11-20
15
Medium Priority
?
241 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans

670 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