2

Here's what I wish to do. Is it possible using a batch (Windows XP) file?

  1. Prompt user to login to a FTP server.

  2. Carry on with the rest of the batch commands, whilst keeping the FTP session/login alive.

  3. Use the FTP PUT command when required with a batch command.

2 Answers 2

2

No, I cannot think of a way to keep the ftp process alive while continuing to run the batch file, and sending commands to the ftp process.

However, if this fits your needs, your batch file can collect all the data it needs first, generate a file containing all the ftp commands, then pass that file to ftp.exe as a last step.

For example:

SET /P ftpuser=Username:
SET /P ftppass=Password:

:: generate ftp script file
ECHO %ftpuser% > ftpcommands.txt
ECHO %ftppass% >> ftpcommands.txt
ECHO put file.txt >> ftpcommands.txt
ECHO quit >> ftpcommands.txt

:: now call ftp and have it process all the commands
ftp -s:ftpcommands.txt server.com
Sign up to request clarification or add additional context in comments.

Comments

2

Windows ftp supports batch processing with its -s switch. However, there is no good way to keep an FTP session alive while waiting for more commands. The ftp command will process its -s script from start to finish and then exit.

Other than having the batch script generate the script used by ftp -s and running it as needed, the only solution I can think of would be to map the FTP server as a drive letter and copy as needed.

2 Comments

This sounds interesting: how would this work? Say I wanted to send a file to FTP server 127.0.0.1. If I mapped this to N:/, what command would I use to send the file?
copy file.ext n:\path\from\ftp\root, just as though you were copying to a flash drive or Windows network share. Please be advised that I've never tried mapping an FTP service to a drive letter via the command line, so I can't say under what circumstances it would fail / succeed. For instance, if the FTP server times out the connection, does a file copy attempt reconnect, or would you have to net use N: /delete and net use N: \\hosts_entry\directory /user:ftpuser ftppass to reconnect? I don't know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.