Solved

Ftp question.

Posted on 2006-11-20
15
197 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
Comment Utility
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
Comment Utility
how do I use a variable in the upload file parameter.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
 

Author Comment

by:casit
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:casit
Comment Utility
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
Comment Utility
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
Comment Utility
The thing still goes in circles.
0
 

Author Comment

by:casit
Comment Utility
And the log file still says mput -i
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Nevermind I just wrote a perl script which was much easier.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
This is about my first experience with programming Arduino.
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 …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now