RADIO ONLINE (Click radio icon to listen)

Sunday 15 February 2015

Title: How to Automate FTP to Download a File From a Server Using Windows Command Line Working With Batch File

How to Automate FTP to Download a File From a Server Using Windows Command Line Working With Batch File



Windows has included batch files since before it existed… Batch files are really old! Old or not, I still could help us to automate common tasks. One common task is uploading files to a remote FTP server. 

Requirements == Must have ftp account (username and password)

Steps (Syntax):
  1. Copy the codes below
  2. Open a notepad and paste into the notepad
  3. Change the parameter.. (FTPUsername, FTPPass, FTPServer, FTPWork, Filename)
  4. Save it as .bat (Example: downloadfile.bat)
@echo off
echo user FTPUsername> ftpcmd.dat
echo FTPPAss>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo FTPWork Filename>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat FTPServer
del ftpcmd.dat

Do you understand?? Let's explain. Let say..

FTPUsername: mircop
FTPPass: mircop1234
FTPWork: get (Get is for download)
Filename: test.txt (You have to create test.txt for dummy try only. The filename is the filename that you wanna upload/download)
FTPServer: ftp.mircop.com

THIS IS THE CODE CREATED FOR ABOVE EXAMPLE (USING PUT, MEANS THAT UPLOAD)

@echo off
echo user mircop> ftpcmd.dat
echo mircop1234>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo get test.txt>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.mircop.com
del ftpcmd.dat
When you double click the batch file, it will shown as below in a prompt box

Connected to ftp.mircop.com.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 10:19. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
ftp> user mircop
331 User mircop OK. Password required
230 OK. Current restricted directory is /
ftp> bin
200 TYPE is now 8-bit binary
ftp> get test.txt
200 PORT command successful
150-Connecting to port 2048
150 6.0 kbytes to download
226-File successfully transferred
226 0.000 seconds (measured here), 49.47 Mbytes per second
ftp: 6122 bytes received in 0.00Seconds 6122000.00Kbytes/sec.
ftp>quit

EXTRA INFORMATION:
1. The batch file uses the “echo” command to send text to the ftp server as if you had typed it. In the middle of the file you can add extra commands before the quit commands, potentionally a change directory command:

echo cd /pathname/>>ftpcmd.dat


If you like this post, kindly linkback to this post entry by copying one of the codes below..

URL Of Post: Paste This HTML Code On Your Page:

3 comments:

  1. superslot เครดิต ฟรี เป็นผู้เก็บทุกค่ายเกมสล็อตมาเอาไว้ในที่เดียว ให้บริการเกมคาสิโนออนไลน์ แบรนด์ดังเยอะมาก สมัครกับ พีจี เพียงแค่ USER เดียวก็สามารถเล่นเกมออนไลน์ได้เลย

    ReplyDelete
  2. เว็บ เกมส์ ออนไลน์ สุดร้อนแรงนาทีนี้ต้อง ที่นี่เท่านั้น กับ PGSLOT-TH.COM เว็บเกมสล็อตออนไลน์น้องใหม่จากค่าย PG SLOT ที่ขนความมันส์มาส่งตรงถึงมือคุณสะดวกสบาย ปลอดภัย 100%

    ReplyDelete