XtremeDocumentStudio
.NET
PDFOne
.NET
XtremeDocumentStudio
(for Java)
PDFOne
(for Java)
XtremeDocumentStudio
Delphi
eDocEngine
VCL
PDFtoolkit
VCL
StarDocs
Web APIs

Gnostice Blog

Tuesday, October 06, 2015

Automating FTP uploads and remote server file management using the Windows ftp scripts

Automating FTP uploads and file management using the Windows ftp command-line program.

By V. Subhash

Microsoft has bundled an command-line FTP program, humbly named "ftp", with every version of Windows released to date. It can be used interactively and can also be run off a script. When you type ftp in the command line, the command starts its own Unix-style prompt against which you run your FTP commands.

To connect to a site, you type open ftp.example.com and to upload a file you type put filename.ext. Or, you could use FileZilla! Yes, even that can be a hassle if you need to do it repeatedly or if you need to make this upload part of a workflow process.

For that, ftp provides a scripting interface. Put all the commands in a file and run the command with -s parameter. (For some reason, the -s parameter does not work in CAPS.)

ftp -s:YourFtpScript.txt

To navigate directories on the remote server, you use the cd command. To do the same in the local system, you use the lcd. You can also prefix exclamation (!) character to any DOS command to run it on the FTP server.

To delete multiple files in the current directory, use the mdelete and to upload multiple files from the local directory, use mput. put works for individual files. Use the binary files, as otherwise the upload may choose ASCII. Use prompt to turn off interactive prompting.

In Linux,


open ftp.example.com
username
password
cd httpdocs/some_path
binary
debug
prompt
mdelete *.*
mput *.*
quit

In Linux, I use a slightly different script.

HOST='ftp.example.com'
USER='username'
PWD='password'

ftp -i -v -n $HOST <<CODEBLOCK
quote USER $USER
quote PASS $PWD

binary

lcd /some_path
cd /httpdocs/some_path
mdelete *.*
mput *.*

CODEBLOCK
exit 0

Notes
Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2018 Gnostice Information Technologies Private Limited. All rights reserved.