3

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://server.com/public_html/folder/folder 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.

  • So why don't you use (scriptable) FTP client with capability to upload new/modified files? – Martin Prikryl Jun 5 '17 at 13:30
7

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@example.com/ 
# 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
exit

Then you just invoke the script from a batch file.

  • I can't install anything. I don't care if the batch file needs to contain 150 lines of code, but it is self-contained and doesn't have dependencies like this does. This should work on any computer on the network without any additional software installed. – InterLinked Jun 5 '17 at 16:14
  • @InterLinked WinSCP does not have to be installed. All you need is to store the executable along with the batch file - And you are right, you would need a script with "150 lines of code" (or more) to solve this without dependencies - Do you really expect anyone to write this for you? You have to do it yourself. And possibly ask for specific problems you find on the way. Programming questions should go to Stack Overflow. – Martin Prikryl Jun 6 '17 at 9:25
  • Are paths like /home/user even used in Windows? That sounds kind of Linxuy – InterLinked Jun 6 '17 at 10:45
  • Where do I put the script above? The portable client I downloaded contains just a COM and EXE file – InterLinked Jun 6 '17 at 10:52
2

From 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)

Map network drive wizard

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
  • Drives are already mapped... that's what I meant by network drive since networks drives must be mapped, otherwise they are just UNC locations. I don't think it's possible to map an FTP folder, otherwise I would be doing it... if it is, that would be great! But when I try doing it, I just get an error – InterLinked Jun 5 '17 at 20:47
  • It is possible to map an FTP folder as a local drive. Did you try step 2? What is the error you are getting? – Genesis_GDK Jun 5 '17 at 23:07
  • Windows cannot access ftp://.... (yet I can access it by going direct into the address bar or using an FTP shortcut I've created). I know I tried a year or so or go to try to map it since I map so many other drives at login with a batch file. But no dice. – InterLinked Jun 6 '17 at 10:48
  • Then this is the problem you need to solve. What Windows version are you running? Have you switched off your firewalls? Have you tried connecting to a different ftp server? Have you tried including your credentials on the connection string? Smething like this: username:password@myFTP.com – Genesis_GDK Jun 6 '17 at 11:12
  • It doesn't work on our organization's Windows 7 domain or at home on our Windows 10 PC. What do you mean credentials string? – InterLinked Jun 6 '17 at 14:22

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.