[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Ftp question.

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
casit
Asked:
casit
  • 8
  • 7
1 Solution
 
sirbountyCommented:
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
 
casitAuthor Commented:
how do I use a variable in the upload file parameter.
0
 
sirbountyCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
casitAuthor Commented:
Now I'm getting the following.
ftp> mput %1
%1:File not found
ftp> close
221 Goodbye
ftp> quit
0
 
sirbountyCommented:
Can you show me what your batch file looks like?
Offhand I suspect it's an issue with long file names or something...
0
 
casitAuthor Commented:
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
 
sirbountyCommented:
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
 
casitAuthor Commented:
But the file I want to send I want to be a parameter when I call the batch script
0
 
sirbountyCommented:
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
 
casitAuthor Commented:
The thing still goes in circles.
0
 
casitAuthor Commented:
And the log file still says mput -i
0
 
sirbountyCommented:
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
 
casitAuthor Commented:
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
 
sirbountyCommented:
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
 
casitAuthor Commented:
Nevermind I just wrote a perl script which was much easier.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now