-1

I have searched the forum and found a few posts related to this question, but the answers I am looking for were not in the posts.

I am pulling my references from this post here.

In this batch file, the user has specified the following:

@echo off
echo user ahk@proflightsimulatoreview.com> ftpcmd.dat
echo ahktest>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.proflightsimulatoreview.com
del ftpcmd.dat

My questions are as follows:

  1. The put command says %1. If I wanted to specify a file in a different directory, could I just put the path of that directory after the put command? Assuming the bat file does not reside in the same dir as the file I want to send.

  2. The put command says %1, and the user executes the MYFTP.BAT c:\temp\hello.txt from the command line. I am not executing anything from the command line but calling the bat file from another application. If I do not want to pass a parameter, can I hardcode in the path and replace the %1?

  3. The ftp command is embedded in the .bat file as ftp -n -s:ftpcmd.dat ftp.proflightsimulatoreview.com. If I wanted to remove the step of writing to a file then calling the file, what is the FTP syntax? What is the advantage of writing to a file and calling a file that you then delete vs just putting the values straight into the FTP command?

Community
  • 1
  • 1
derrickt
  • 3
  • 2

1 Answers1

0

Firstly, I would recommend you put your %1 in double quotes in your script in case your filename has a space in it, i.e. in case the user does:

MYFTP.BAT "C:\Programs and Junk\Path with Space\file.txt"

Questions 1 & 2 share a common underpinning, which when you understand it, will help you see they are related. When you do:

PUT FILE.TXT

the FTP protocol takes FILE.TXT in the current directory, and because you have not specified a destination file it puts it in the current directory on the FTP server with the same name. So, you are going to have problems if you do this:

PUT C:\FREDDYFROG\FILE.txt

unless the FTP server has directory called "C:\FREDDYFROG" which is extremely unlikely on a Unix server! So you should consider specifying a filename on the server as follows:

PUT C:\FREDDYFROG\FILE.TXT SomeFile.txt

Further more, you can change directory on the server, with CD so that uploaded files "land" in a different directory on the server. You can also change directory locally on your machine with LCD. So the following command will upload local file \FREDDYFROG\FILE.TXT into the server's filesystem at /incoming/somefile.txt

LCD \FREDDYFROG
CD /incoming
PUT FILE.TXT somefile.txt

as will the following

PUT \FREDDYFROG\FILE.TXT /incoming/somefile.txt

Finally, your third question. You have to put the commands in a file with Microsft's FTP client, it doesn't read commands from standard input as far as I know.

You may prefer curl over Micorosft's FTP client if available and that will obviate the need to create temporary script files and do the whole lot in one go like this:

curl -v -u user:password -T \FREDDYFROG\FILE.TXT ftp://server/mydir/somefile.txt
Mark Setchell
  • 146,975
  • 21
  • 182
  • 306