How to copy new files in a folder to an FTP location using a batch file?
There are many questions on SuperUser about uploading a single file to an FTP server, but not many about uploading entire folders, so I doubt this is a duplicate question.
I don't use an FTP client - I always just access my FTP server like any folder using Windows Explorer. After I authenticate, I can just browse the contents of my site just like a regular directory.
Usually, when I want to edit something on my website, I login to the FTP directory, copy the file I want to edit to my Downloads folder (it could be any local folder, I just find that easy), edit what I need to, and then move/copy it back. I only have a small website and I've coded all of it from scratch myself so I don't need to worry about server-side anything.
In the past, I've tried using a batch file to login to the FTP server automatically and open public-html in an Explorer window, and I couldn't get that to work. I'm wondering if it's possible to in a self-contained batch file to copy all of the new/changed files from a specific folder in a mapped network drive to the appropriate folder in the FTP server. I'm assuming I can use ftp:// as a path and Windows will use Explorer for that. If it could also login to the server, that would be helpful, but I can login manually.
Otherwise, it's very cumbersome to manually copy each file that I've changed from my testing area to the FTP server.
A PowerShell or VBS script would suit me as well; I just need to be able to develop a self-contained file that doesn't have any dependencies (i.e. I don't want to install a client or any software packages).
I can easily write a script to copy files from one mapped drive to a folder on a local disk, and I don't know why FTP should be any different.
12 Answers
All the operations you're mentioning in your post can be automated with a WinSCP script. Have you tried WinSCP? It's super-powerful and free with tons of support. Below, is an example script of what your actions would look like:
# Connect
open ftp://user:password@
# Change remote directory
cd /home/user
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
get examplefile.txt d:\
# This will Upload whole folder files and subfolders to current working directory
put d:\
# Disconnect
close
# Exit WinSCP
exitThen you just invoke the script from a batch file.
2From your question I suppose you are asking the following:
copy all of the new/changed files from a specific folder in a mapped network drive to the appropriate folder in the FTP server.
Step 1.
Use net use to mount a network location as a drive name (Or use the windows wizard to map a network drive)
net use Z: \\MyServer\MyShare\Where Z: is the drive letter you want to use
Step 2.
Map another drive with a different letter only this time, make it an FTP server (see screenshot)
You will end up with two drives which you can copy files with windows Explorer but also from the command prompt like so:
copy Z:\myFiles Y:\public_html\folder\folder 5