List of FTP commands

! Escape to the shell
? Print local help information
append Append to a file
ascii Set ASCII transfer type. Use this to transfer text files, such as .htm files. See www.superior-host.com/webhosting-guide/linux-files.html for an excellent discussion of when to use ascii mode and when to use binary mode.
bell Beep when command completed
binary Set binary transfer type. Use this to transfer binary files such as .exe files and graphics (see also ascii).
bye Terminate the FTP session and exit
cd Change remote working directory ( use .. to go to parent)
close Terminate FTP session
delete Delete remote file
debug Toggle debugging mode
dir List the contents of the remote directory
disconnect Terminate the FTP session
get Receive file (see also mget)
glob Toggle metacharacter expansion of local file names
hash Toggle printing ‘#’ for each buffer transferred
help Prints list of commands
lcd Change the local working directory
literal Send an arbitrary FTP command
ls List contents of remote directory
mdelete Delete multiple files
mdir List the contents of multiple remote directories
mget Get multiple files (see also get)
mkdir Make a directory on the remote machine
mls List contents of multiple remote directories
mput Send multiple files (see also put)
open Connect to remote FTP
prompt Force interactive prompting on multiple commands (this is a toggle)
put Send one file (see also mput)
pwd Print working directory on remote machine
quit Terminate FTP session and exit
quote Send an arbitrary FTP command. You can view a list of raw FTP commands on www.nsftools.com/tips/RawFTP.htm
recv Receive file
remotehelp Get help from remote server
rename Rename a file
rmdir Remove a directory on the remote machine
send Send one file
status Show current status
trace Toggle packet tracing
type Set file transfer type
user Send new user information
verbose Toggle verbose mode

Difference Between COPY and XCOPY

COPY does a shallow copy (doesn’t recurse into sub directories) while XCOPY has the option to do a recursive copy which will copy all files and sub folders within the target folder that you are copying. if you’re just copying one single file, either one will suffice.

Create a Disaster Recovery Copy of Your Files in Real Time

1) Create a batch file with the following code:

xcopy /d /s /y “\\networkPC\e$\foldertobackup” “E:\BackupFolder”

2) Create Windows Scheduled Task

3) Point Windows Scheduled Task to the batch file created in Step 1

4) Make Windows Scheduled Task to run “Daily” starting from 5 am in the morning (before start of the working day)

Scheduled Windows (PC) Restart Using DOS command (shutdown.exe)

1.Create a batch file “restart.bat” with the following code shutdown -r -t 60 -c “Rebooting computer”
2.Create a scheduled task that would execute restart.bat

How to execute a “batch file” using SQL Server 2005?

One method is with a SQL Server agent CmdExec job step. Another is via xp_cmdshell. If you choose to use xp_cmdshell, be sure you fully understand the security implications and don’t grant direct execute permissions on the proc.

How to: Create a CmdExec Job Step

By default, only members of the sysadmin fixed server role can create CmdExec job steps. These job steps run under the context of the SQL Server Agent service account unless the sysadmin user creates a proxy account. Users who are not members of the sysadmin role can create CmdExec job steps if they have access to a CmdExec proxy account.

  1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
  2. Expand SQL Server Agent, create a new job or right-click an existing job, and then click Properties.For more information about creating a job.
  3. In the Job Properties dialog, click the Steps page, and then click New.
  4. In the New Job Step dialog, type a job Step name.
  5. In the Type list, choose Operating system (CmdExec).
  6. In Run as list, select the proxy account with the credentials that the job will use. By default, CmdExec job steps run under the context of the SQL Server Agent service account.
  7. In the Process exit code of a successful command box, enter a value from 0 to 999999.
  8. In the Command box, enter the operating system command or executable program.
  9. Click the Advanced page to set job step options, such as: what action to take if the job step succeeds or fails, how many times SQL Server Agent should try to execute the job step, and the file where SQL Server Agent can write the job step output. Only members of the sysadmin fixed server role can write job step output to an operating system file.

What is XP_CMDSHELL

“xp_cmdshell” is an extended stored procedure provided by Microsoft and stored in the master database. This procedure allows you to issue operating system commands directly to the Windows command shell via T-SQL code. If needed the output of these commands will be returned to the calling routine.

Only users in sysadmin role can execute xp_cmdshell stored procedures.

If a login executing this extended stored procedure is a member of the sysadmin role then the submitted command will run under the security context associated with the SQL Server Service account in which it runs.

By default XP_CMDSHELL is turned off in SQL Server 2005

TO ENABLE XP_CMDSHELL run this code:

EXECUTE sp_configure ’show advanced options’, 1
RECONFIGURE WITH OVERRIDE
GO
EXECUTE sp_configure ‘xp_cmdshell’, ‘1′
RECONFIGURE WITH OVERRIDE
GO
EXECUTE sp_configure ’show advanced options’, 0
RECONFIGURE WITH OVERRIDE
GO

Start .EXE, .BAT or .COM file from batch file

If you want the start command to run the MENU.EXE file that’s located in say the root directory of drive C:, you would type:

start c:\menu.exe

If you want the start command to run the MENU.BAT file that’s also located in the root directory of drive C:, you would type:

start c:\menu.bat

If you had a MENU.EXE, MENU.BAT and a MENU.COM all located in the same directory and you didn’t specify which one you wanted to run, like so:

start c:\menu

DOS would start the MENU.COM file. If MENU.COM didn’t exist it would start the MENU.EXE file. If MENU.EXE didn’t exist it would start the MENU.BAT file. In other words, if you don’t specify which one you want to run, DOS looks for .COM files first, then .EXE then .BAT. To keep it from doing this, simply specify which one you want DOS to run, i.e.,

DOS/Batch Commands/Functions Descriptions

DEL and ERASE

In Windows NT, the DEL and ERASE commands are much more powerful than they are in other versions of MS-DOS and Windows. Although the basic syntax remains the same, Windows NT offers several switches that allow DEL to behave like the DELTREE command. Using the appropriate switches, it’s also possible to delete files with specified attributes. You can even make the deletion process confirm a delete, or make the deletion process invisible. You can find out all of the details by typing del /? at the command prompt.

COLOR

Tired of that boring black and gray command prompt? You can use the COLOR command to make your batch files look more like professional programs. To do so, simply use the COLOR command followed by two hexadecimal numbers. For example, the command COLOR 17 makes the screen blue with white writing. You can choose from 16 colors, each of which can be used in the foreground or the background. To see a list of available colors and their corresponding numbers, type color /? at the command prompt.

CD and CHDIR

Windows NT contains enhanced versions of the CD and the CHDIR commands. Although both commands employ the usual syntax, two enhancements are worth mentioning. First, you can add the \D parameter to change drives as well as directories. This parameter could save you a few lines in a batch file. For example, the command:

CD /D E:\DATA

does the same thing as the following set of commands:

E:
CD\DATA

The commands have also been modified to enable extra support for directory names that contain spaces. For example, in the past, if you wanted to change to the \My Documents directory, you had to type cd “\My Documents.” With the enhanced commands, it’s now possible to enter the command without the quotation marks.

MD and MKDIR

The MD and MKDIR commands have been enhanced to save you a lot of work. Now, you can create large directory structures with a single command. For example, now you can type a command such as:

MD \DATA1\DATA2\DATA3\DATA4

In the past, you had to create the DATA1, DATA2, and DATA3 directories manually before you could create the DATA4 directory. The command we just typed creates them all at once. For example, the command:

MD \DATA1\DATA2\DATA3\DATA4

takes the place of the following lines:

CD\MD DATA1
CD DATA1
MD DATA2
CD DATA2
MD DATA3
CD DATA3
MD DATA4
CD\

PROMPT

You’re probably already familiar with the PROMPT command and some of its attributes. For example, the command PROMPT $P$G displays the drive letter and the current path as the prompt. This command has become standard in recent years. However, Windows NT provides additional attributes that let you display things like the current time, the Windows NT version number, or—more importantly—the full network path. You can learn more about the PROMPT command by typing prompt /? at the command prompt.

PUSHD and POPD

The PUSHD and POPD commands work together. PUSHD captures the name of the current directory. You can also add the name of a directory that you would like to change to. For example, the command PUSHD \DATA1 will switch you to the DATA1 directory (but remember the name of the directory you’re currently in). To automatically return to this directory, simply type POPD.

SET

You’re probably already familiar with the SET command, which you use to assign a particular value to an environment variable. For example, the command:

SET TEMP=C:\TEMP

would assign the value C:\TEMP to the variable TEMP. In Windows NT, the SET command has been greatly enhanced to let you perform such actions as combining strings or separating parts of a string. For example, it’s now possible to take a string, strip off the first five characters, and copy the next seven characters to another variable. Although space doesn’t permit us to discuss all of the intricacies of the SET command in this article, you can find out more about it by typing set /? at the command prompt.

SETLOCAL and ENDLOCAL

The SETLOCAL and ENDLOCAL commands are used together. When you use the SETLOCAL command within a batch file, any environment changes you make after that point are local to the batch file. For example, if you used the SETLOCAL command followed by the:

SET TEMP=C:\TEMP

command, the batch file would recognize the TEMP variable as containing the string C:\TEMP. However, if you were to run a different batch file or open a different MS-DOS Window, the TEMP variable wouldn’t contain this string. To prevent future environment variable changes from being local, you can use the ENDLOCAL command.

IF

The IF command works similarly to the way that it does in MS-DOS or in other versions of Windows. You can still compare error levels and strings and check to see if a filename exists. The NOT parameter also still works. However, where the new and improved IF command really shines is in the added enhancements. For example, when comparing strings, you can now test to see if they’re equal, not equal, less than, less than or equal to, greater than, or greater than or equal to. There’s even a switch you can use to make the comparison case sensitive or case insensitive. Furthermore, IF now includes a DEFINED command that returns a TRUE value if an environment variable has already been defined. As you can see, the added capabilities of the IF command can greatly enhance your batch files. If you want to know more about the IF command, type if /? at the command prompt.

FOR

The FOR command still supports the same parameters that it always has, enabling you to test for and act on the presence of a string in a group of files. However, Windows NT contains several enhancements to this command. For example, you can now work with directories or directory trees instead of just files. You can also work with counters. For example, if you wanted to test for even numbers between 16 and 128, you could use the FOR command to do so. There are even some advanced commands for parsing files and filtering out or changing data. You can read all about these enhancements by typing for /? at the command prompt.

CALL

The CALL command allows your current batch file to pass information to and execute another batch file. The CALL command now supports several labels that you can use to pass specific information such as a drive letter, a path name, file names and extensions, and other information. You can read all about the CALL command by typing call /? at the command prompt.

SHIFT

The SHIFT command changes the position of arguments within a batch file. You can even specify the position to which you want to begin shifting the arguments. For example, typing SHIFT /2 begins shifting positions after the second argument. You can shift values in the first (%0) through ninth (%8) positions.

GOTO

If you’ve ever written a batch file that had several different sections that could execute depending on the value of a variable, you’re probably familiar with the GOTO command. However, in the past, it’s always been necessary to create a label at the bottom of the file and add a statement to each section to go to this label. Doing so prevents other sections of the file from running when they aren’t supposed to. Figure D shows an example of such a file. Notice how each section of the batch file ends by calling the END section. The END section doesn’t actually contain any instructions, but we still had to include it so our batch file would execute properly. However, Windows NT allows you to call a label called EOF without actually creating an EOF section. When the command interpreter reaches such a statement, it ends the batch file.

Run a specified program only on certain days at boot time.

This demo makes use of two tricks: It reads a custom INI file, and it puts the current day into the environment.

@echo off
:: This batch file allows you to run programs on certain days.
:: Have this TODAY.BAT program CALLed from your AUTOEXEC.BAT.
:: TODAY.BAT will read entries in a TODAY.INI file you must make.
:: The entries in the TODAY.INI should look like this:
:: 10-12-1999=DeleteOldDocs.bat
:: 10-13-1999=Scandisk.bat
:: 10-14-1999=PrintReports.bat

:: Put the date into the DATE environment variable
:: Response to DATE command should be like
:: Current date is Sun 10-12-1997
:: Enter new date (mm-dd-yy):
@echo.|date|find /i “current”>#urrent.bat
@echo set date=%%4>current.bat
call #urrent.bat
del ?urrent.bat

:: Put the command for today into TODAYSCOMMAND variable
:: Assumes existence of TODAY.INI in current directory
find “%date%=” today.ini | sort /r | date | find “=” > en#er.bat
@echo set todayscommand=%%5> enter.bat
call en#er.bat
del en?er.bat > nul

:: Cleanup - delete DATE variable and INI entry (so it only runs once)
type today.ini|find /v “%date%”>today.ini
set date=

:: Run today’s command
call %todayscommand%
set todayscommand=

:: _____________________________________________________
:: If the command for the day requires user input, for
:: example, you have to hit enter or answer yes or no,
:: you should run a separate batch file instead of
:: running the command directly. Assume you want to run
:: CHKDSK with the /F option to fix errors. If it finds
:: errors, it will ask you to type “y” or “n”.  You can
:: create a batch file which will do this for you:
:: ECHO Y|CHKDSK /F
:: If all you need is to press “Enter”, you can do this:
:: ECHO.|CHKDSK /F
:: If you need to press “y”, AND THEN HIT “Enter”, it
:: gets more complicated. You have to create what is
:: generally called a “script” containing the exact
:: keystrokes you need to press. You can create it
:: ahead of time, or as needed like this:
:: ECHO Y>SCRIPT.TXT
:: ECHO.>>SCRIPT.TXT
:: TYPE SCRIPT.TXT|CHKDSK /F
:: Notice the first line had only one “>”, but the
:: second line had two “>>”. Just one will cause
:: the SCRIPT.TXT to be created new (if it already
:: exists, it will be erased to start over fresh).
:: The two >> will cause things to be appended to
:: the existing SCRIPT.TXT

Have your batch file send the desired answer..

Have your batch file to anser “Do you really want to do this?” prompt.

If you find yourself trying to automate the deletion of files, the formatting of floppies, or do anything else REALLY INTERESTING, you’re going to hit a spot where everything stops and you get asked “Are you sure?”. Sometimes you can pass a “/y” on the command line (like the COPY command) to override this, but that’s the exception. Often, you can simply ECHO the key you’ll need to press into the command. As an example, suppose you want to run CHKDSK with the /F option to fix errors. If it finds errors, it will ask you to type “y” or “n”.  You can create a batch file which will do this for you:

————
ECHO Y|CHKDSK /F
————

If all you needed to do was to press “Enter”, you could do this:

————
ECHO.|CHKDSK /F
————

If you need to press “y”, AND THEN HIT “Enter”, it gets more complicated. You have to create what is generally called a “script” containing the exact keystrokes you need to press. You can create it  ahead of time, or as needed like this:

————
ECHO Y>SCRIPT.TXT
ECHO.>>SCRIPT.TXT
TYPE SCRIPT.TXT|CHKDSK /F

————

I use CHKDSK above because it is harmless as an example, not because it works. If I told people how to format their hard drives, some people would type in the code to test it. CHKDSK hasn’t been a usable command since Windows 95. The technique is correct though!

Use the “pipe” character “|” (the vertical bar) to send the output from a command into the input of another command.

For example:
type test.txt | program.exe

That would send the output of the “type” command into the input of the “program.exe” command. The “type” command in this case would be putting out the contents of the file “test.txt”. The “program.exe” would (in theory) accept that as it’s input instead of accepting input from the keyboard.

Use redirection characters “>” and “<” to send output between files and programs. Notice the difference? The pipe sends stuff between two PROGRAMS. Redirection is between a program and a FILE. The redirection arrow lets you know what direction the data is flowing.

For example:
program.exe > test.txt

would take the output of “program.exe” and put it in the file “test.txt” INSTEAD of displaying it on the screen. The data flows out of the program “program.exe” and into the file “test.txt”. On the other hand:

program.exe < test.txt

Would cause “program.exe” to use “test.txt” as it’s input INSTEAD of taking input from the keyboard. The dat flows out of the file “test.txt” into the program “program.exe”.

So these two lines are different ways of doing the same thing:

type test.txt | program.exe

program.exe < test.txt

The both end up “program.exe” to use the data in “test.txt” for input instead of using the keyboard.

The difference between “>” and “>>” is that “>” normally creates a new file, replacing what was there, while “>>” just adds to the end of the file (If the file doesn’t already exist, it will be created).

You can even use redirection in non-intuitive order and it still works. For example, these two lines do the same thing:

program.exe > test.txt
> test.txt program.exe

Looks cute, but it’s confusing, huh? Stick with the normal way.

So now you know enough to try redirecting or piping into the program that stops in DOS and asks questions.

HOWEVER — Sometimes programs will clear the keyboard buffer before they ask for user input. This has the effect of ignoring everything you pipe or redirect into the program! If that’s the case, you have to fall back to using a separate keyboard sinulator program to type the needed keys in.

Get user input from batch file

Sure, you’ve done it, but can you do it without having to hit a Ctrl-Z, without ANSI, without a debug script, and without a separate “set” file?

rem  This batch file gets a character or word of user input and
rem  returns it in the environment variable VALUE. Two tricks are
rem  used to accomplish this:
rem
rem  (1) The FC (File Compare) command is used to compare two standard
rem      devices — NUL (nothing) and CON (the console). The /LB1 option
rem      is used to insure only one line is compared, and the /N numbers
rem      that output line with a “1:”, making it easier for us to find.
rem      FC will output immediately after the user hits “Enter” (because
rem      of the /LB1), and will give us a total of 7 lines of output.
rem      Of these 7 lines, the one starting with “1:” is the one we want.
rem
rem  (2) The DATE command is used only because it always returns the
rem      phrase “Enter new date (mm-dd-yy): ” followed by whatever was
rem      piped into it. Why is this format important?  Obviously, it
rem      has nothing to do with setting the date!  Well, we will be
rem      piping it into a batch file and running it. When that batch
rem      file runs, it will try to execute the first word (Enter) as if
rem      it were a valid command, and pass everything else as arguments.
rem      Since we have created a valid (batch file) command called ENTER,
rem      this will actually work! We just have to make sure that ENTER.BAT
rem      is set up to handle the arguments that will be passed to it!

echo This is a test. Please enter “y” or “n”
fc con nul /lb1 /n | date | find “1:” > en#er.bat
echo set value=%%5> enter.bat
call en#er.bat
del en?er.bat > nul
if “%value%”==”n” echo You entered “n”
if “%value%”==”y” echo You entered “y”
set value=

rem      See PC Magazine V14N12 June 27, 1995 page 248 for further
rem      information. The PC Magazine article suggests using a
rem      permanent ENTER.BAT which can accept a line
rem      of user input (complete with spaces between words!).
rem      My version is meant to be inserted into any batch file
rem      and will create a simple one-line temporary ENTER.BAT in
rem      the default directory and on the fly as needed.