Home > How To, Internet, Software, Tutorial, Tweak > Automate FTP Upload Using Commandline

Automate FTP Upload Using Commandline

April 16th, 2009 Leave a comment Go to comments

Here’s an an example. Consider that you need to automate uploading any file(s) to your site, say prashanthpai.com. You’ll require this if you need to update the same file(s) very frequently.

  1. Open notepad and type the following and save it as “upload.ftp“. You can save it with any name and any extension. Don’t save it as txt file. It works perfectly but others can open and see the ftp username and password easily.

    open prashanthpai.com
    username
    password
    cd public_html/downloads
    put C:MySitego.exe
    bye

    • First line will make connection to ftp server at prashanthpai.com
    • Don’t forget to replace prashanthpai.com with your site name or IP address.
    • Enter you ftp username and password in second and third line respectively.
    • Next is you’ve got type the path on your server where you need to upload the files. When you login to ftp, usually you are in the root direcrory or ““. In case of linux(like cPanel) the path would be public_html and in case of windows(like Plesk), path will be httpdocs.
    • The put command uploads the file. You need to give the full path of the file to upload.
    • In the last line, bye command terminates the ftp session.
  2. Next you need to create a batch file in the same directory where you’ve created “upload.ftp“. Open notepad and type the following code. Save it with any name with .bat extension like “Auto_FTP.bat“.

    @echo off
    ftp -s:”upload.ftp” >> ftplog.log

    The above batch script will tell ftp utility to load the commands from the file “upload.ftp“. To check the file transaction, a log file named “ftplog.log” is created. You can remove “ >> ftplog.log” from the script if you don’t want the log file.

  3. Run the Auto_FTP.bat. Your file will be uploaded to the destination folder on your site :)

Note: If you want to upload multiple files, you need to change the upload.ftp file code as

open prashanthpai.com
username
password
cd public_html/downloads
mput C:MySite*.exe
bye

Note the mput command instead of put. Change the batch script as

@echo off
ftp -i -s:”upload.ftp” >> ftplog.log

Note the extra -i switch in the above code. This will upload all files from C:MySite having .exe extension.

P.S: This tutorial was first posted by me at Raymond.cc forum.

  1. No comments yet.
  1. No trackbacks yet.