Download a file from an FTP using a batch script.

Solved
2berte Posted messages 217 Status Member -  
 Garfunkel -
Hello,

I want to upload a file to an FTP server. To do this, I want to create a batch file so I can run it tonight to download.

First, I tested it in DOS, and it works very well. Here are the commands:
ftp
open monFTP.com
username
password
cd MyDirectory
lcd C:\
mget myFile.txt
quit


Then I tried to automate it in a batch file...

ftp
open monFTP.com
User username password
lcd c:\
cd myDirectory
mget myFile.txt
quit
pause


But I'm stuck on the ftp line. In my console, there’s a blinking ftp line, and if I press enter, I get the same thing again. I think this is normal because the ftp command is an application.

So I tried to externalize the FTP command. I ended up with two files: one that launches the ftp command and retrieves a processing file. This processing file is exactly what I would type as a DOS command.

My bat file: ftp -s: "D:\Desktop\processing.txt"

My processing file:
open monFTP.com
myUser
myPassword
lcd c:\
cd myDirectory
mget myFile.txt
quit
pause


But my bat file does not read the processing file. Do you know where the error could be?

Looking forward to your response,

Best regards

2berte
Configuration: Windows Internet Explorer 8.0

2 answers

2berte Posted messages 217 Status Member 143
 
Thank you, for the link I was able to self-correct! I did look for solutions online...

So here is my final script:

1st file: .bat file:
ftp -s:D:\Bureau\config.txt -n
-s indicates the path of the processing file to execute, be careful there is no space between the ":" and the file name.
-n means that authentication is done manually, we do not propose it at the beginning.

2nd file: processing file:

open NomDuFTP
user login password
get test.txt
close
quit


This snippet of code allows downloading a file test.txt placed at the root of the ftp. It will be downloaded to the user's default directory (e.g., C:\Users\XXX\test.txt).

To place the file in another directory, you simply need to indicate another path with the lcd command, for example lcd D:\MesDocs\

Hoping this snippet of code can be useful to others.

Best regards

2berte
10
fatome
 
Thank you for the feedback!
0
Garfunkel
 
thank you for the helping hand
0
kiki
 
Hello,

See the example here: https://forum.hardware.fr/hfr/WindowsSoftware/ligne-commande-sujet_101423_1.htm
It must be a command error: it's get or send.

Best regards,
0