简体   繁体   中英

Windows batch - ftp uploading and connection

I would like to upload a file to my ftp server if internet is connected

In each run, i prefer:

if (ftp server can be connected){
   upload the file "C:\abc.txt" to the ftp server directory "/ABC_DB"
}

Thus, I am not sure how to check ftp connection, is it possible to run like this:

echo abc > C:\abc.txt
???Check the connection here 
OPEN your.ftp.server.com
usernameabc
passwordbcd
CD /ABC_DB
PUT "C:\abc.txt"
QUIT
PAUSE

Sorry for asking such silly question, but I am new in batch, hope u can help me =[

Test this: change lines 2,3,4 with your details

@echo off
set "name=your_ftp_user-name"
set "password=your_ftp_password"
set "server=ftp_server_name"

ping %server% |find /i "TTL=" >nul || (echo server offline, aborting&pause&goto :EOF)

set "ftpScript=%temp%\%~nx0.ftp.tmp"
(
    echo open %server%
    echo %name%
    echo %password%
    echo bin
    echo CD /ABC_DB
    echo PUT "C:\abc.txt"
    echo quit
) > "%ftpScript%"

ftp -i -s:"%ftpScript%"
del     "%ftpScript%"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM