3

So I am trying to write a small batch program to copy files over ftp to another device The problem is the devices I am copying to are all different servers, but the information i'm copying stays the same. How can I write this so when I open the batch program, i specify the IP address of the device, and the batch will connect to the server automatically and copy the directories or files i need copied.

Currently it will allow me to input the IP, connect to the server and open a specific file, but every time it tries to connect to copy files it says invalid directory or incorrect server.

:Log
set /p PDTFTP= Enter PDT IP Address: 
start "ftp://admin:2p0d0t7@%PDTFTP%/pub/IPSM/fds/log/PDTApplicationLog.txt"

:DB 
set /p PDTFTP= Enter PDT IP Address: 
xcopy "C:\test.txt" "ftp://admin:2p0d0t7@%PDTFTP%/pub/IPSM/fds/"

Is there a way to do this when the ftp server will be different almost every time its used

4
  • What are you typing exactly? Jul 31, 2017 at 11:16
  • Well, what I pasted in the original comment was what I was attempting, i know xcopy wont work for FTP, but because of the nature of the devices used where I work connecting to the FTP server for them is a pain in the ass. For example the full FTP link above with the IP address in place on %PDT%, If I paste it in explorer it connects immediately with no prompt to login, but programs like filezilla will not connect, even though the geniuses in my office repeatedly tell us to use it after they blocked it... Aug 1, 2017 at 3:53
  • The part under :DB is the only part not working, im just trying to copy release files from one server to the devices itself since we dont have an automated program for it Aug 1, 2017 at 3:55
  • So does the answer by @Hacker help you or not? Do you need any more information? Aug 1, 2017 at 6:32

1 Answer 1

2

You could do it like this:

to download the file:

@echo off
set /p ip=IP:
echo username> temp.txt
echo password>> temp.txt
echo get fileToGet>> temp.txt
echo quit>> temp.txt
ftp -s:temp.txt %ip%
del temp.txt

to upload the file:

@echo off

set /p ip=IP:
echo username> temp.txt
echo password>> temp.txt
echo put fileToUpload>> temp.txt
echo quit>> temp.txt

ftp -s:temp.txt %ip%
del temp.txt
1
  • After a few failed attempts this method did work, I had to use the -n tag then -s for it to work. Thanks! Aug 7, 2017 at 2:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.