Re: Replace Existing Folder

I created the batch file and script file below. But it does not work. What am I doing wrong?

Batch file:

set LOCAL=%1
set REMOTE="/home/user/www/%~n1%~x1"
winscp.com /script=example.txt

Script file:

open session
delete %REMOTE%
put %LOCAL% %REMOTE%

Andevorea

Re: Replace Existing Folder

2009-05-07 05:35

Andevorea wrote:

Maybe the best solution would be a script that simply has two steps: delete and upload. Here is how it would work:

Step #1: Delete "XYZ" folder from the server. When step #1 is completed, go to step #2. If it is impossible to complete step #1 (because "XYZ" folder does not already exist on the server), gracefully quit step #1 and go to step #2.

Step #2: Upload "XYZ" folder to the server.

That script would be used in this type of scenario:

I sit down at my computer with WinSCP not yet opened. In Windows Explorer, I right-click on "XYZ" folder and click Send To > MyShortcut. Then all of the following happens automatically without any further clicks: WinSCP opens; WinSCP opens a connection to my FTP server; if "XYZ" folder already exists on the server in root/MyServerFolder, WinSCP deletes "XYZ" folder from the server; WinSCP uploads "XYZ" folder to root/MyServerFolder; WinSCP closes the connection to my FTP server; WinSCP closes.

Please post the shortcut and script code.

Andevorea

Re: Replace Existing Folder

2009-05-01 06:49

Maybe the best solution would be a script that simply has two steps: delete and upload. Here is how it would work:

Step #1: Delete "XYZ" folder from the server. When step #1 is completed, go to step #2. If it is impossible to complete step #1 (because "XYZ" folder does not already exist on the server), gracefully quit step #1 and go to step #2.

Step #2: Upload "XYZ" folder to the server.

martin

Re: Replace Existing Folder

2009-04-30

Andevorea wrote:

I would prefer to have only one shortcut, which will be used in all situations. Please post the "complicated scripting" code.

It would take some time. May do once. Cannot promise.

Andevorea

Re: Replace Existing Folder

2009-04-27 23:14

martin wrote:

OK, that's true. You cannot do this with one connect without complicated scripting. Simple solution is to make another shortcut for initial upload, where you execute a script, where "synchronize remote" is replaced with "put"

I would prefer to have only one shortcut, which will be used in all situations. Please post the "complicated scripting" code.

martin

Re: Replace Existing Folder

2009-04-22

Andevorea wrote:

I am assuming there is a typographical error in that post. I assume you mean "to make another shortcut" where you said "not make another shortcut". Am I correct about that?

OK, correct. Fixed.

Andevorea

Re: Replace Existing Folder

2009-04-20 13:20

martin wrote:

OK, that's true. You cannot do this with one connect without complicated scripting. simple solution is not make another shortcut for initial upload, where you execute a script, where "synchronize remote" is replaced with "put"

I am assuming there is a typographical error in that post. I assume you mean "to make another shortcut" where you said "not make another shortcut". Am I correct about that?

martin

Re: Replace Existing Folder

2009-04-20

OK, that's true. You cannot do this with one connect without complicated scripting. Simple solution is to make another shortcut for initial upload, where you execute a script, where "synchronize remote" is replaced with "put"

Andevorea

Re: Replace Existing Folder

2009-04-20 00:12

OK, it is working now. But I am not accomplishing everything that I want to accomplish.

This quote (from an earlier post in this thread) tells everything that I want to accomplish:

Here is what I want to want to be able to do: I sit down at my computer with WinSCP not yet opened. In Windows Explorer, I right-click on "XYZ" folder and click Send To > MyShortcut. Then all of the following happens automatically without any further clicks: WinSCP opens; WinSCP opens a connection to my FTP server; if "XYZ" folder already exists on the server in root/MyServerFolder, WinSCP changes the server "XYZ" folder to make it exactly the same as the local "XYZ" folder; if "XYZ" folder does not already exist on the server in root/MyServerFolder, WinSCP simply uploads "XYZ" folder to root/MyServerFolder; WinSCP closes the connection to my FTP server; WinSCP closes.

I am accomplishing everything in that quote, except the following:

if "XYZ" folder does not already exist on the server in root/MyServerFolder, WinSCP simply uploads "XYZ" folder to root/MyServerFolder

If "XYZ" folder does not already exist on the server in root/MyServerFolder, WinSCP is unfortunately doing nothing.

martin

Re: Replace Existing Folder

2009-04-17

OK, than change the command from winscp.com to winscp418.exe. But this way you will get two console windows on desktop (only cosmetic issue). You would better install WinSCP to get winscp.com.

Andevorea

Re: Replace Existing Folder

2009-04-15 11:51

martin wrote:

You have to run the .bat file from the same directory, where winscp.com is (C:\Program Files\WinSCP\). Also make sure the shortcut has this directory set as start directory.

In my last post, I incorrectly said: "Every detail that you described was true when I posted my April 11 message, and I have confirmed that it continues to be true." Here is what I should have said:

All of these details were true when I posted my April 11 message, and I have confirmed that all of these details continue to be true: I am running the .bat file from the "C:\Program Files\WinSCP" directory, and the shortcut has this directory set as start directory. But I have never seen a file named "winscp.com".

Andevorea

Re: Replace Existing Folder

2009-04-15 11:21

martin wrote:

You have to run the .bat file from the same directory, where winscp.com is (C:\Program Files\WinSCP\). Also make sure the shortcut has this directory set as start directory.

Every detail that you described was true when I posted my April 11 message, and I have confirmed that it continues to be true.

I am continueing to have the same problem that I described on April 11. I am very frustrated. If you are not sure what the solution is, please give me several *possible* solutions, and I will try all of them.

On your own computer, please do everything that I have done, and tell me the results. Make sure you use WinSCP "Portable executable".

Please tell me: what exactly is "winscp.com"??? Is that the name of a file that is supposed to be in my WinSCP folder? There is no such file in that folder. Here is a list of all files in that folder (C:\Program Files\WinSCP):

example.txt
MyBatch.bat
winscp418.exe
winscp418.ini

martin

Re: Replace Existing Folder

2009-04-14

You have to run the .bat file from the same directory, where winscp.com is (C:\Program Files\WinSCP\). Also make sure the shortcut has this directory set as start directory.

Andevorea

Re: Replace Existing Folder

2009-04-14 10:25

Please keep in mind that I am using WinSCP "Portable executable". Could that possibly be the cause of the problem? Is it possible that Windows may be looking in the registry for "winscp.com" and not finding it because WinSCP "Portable executable" does not use the registry? I'm just guessing about that stuff, and I admit that I actually don't know much about WinSCP. In fact, I don't even know what "winscp.com" is.

Andevorea

Re: Replace Existing Folder

2009-04-14 08:21

Since my last post, I did a bit of research and learned how to execute the batch file from command line. Here is the results:

Re: Replace Existing Folder

Thanks for publishing that article. I followed the instructions in that article, but unfortunately it did not work. I am a WinSCP newbie, and this is the first time that I have made a script or batch file for WinSCP; so I may have possibly done something wrong. Please let me know if I did, in fact, do something wrong.

Here is what I did.

I created MyBatch.bat file, which contains the following code:

set LOCAL=%1
set REMOTE="/MyServerFolder/%~n1%~x1"
winscp.com /script=example.txt

I placed the MyBatch.bat file in my WinSCP folder.

I created a shortcut to the MyBatch.bat file. I named the shortcut MyShortcut. I placed MyShortcut on the desktop. I placed a copy of MyShortcut in my Windows SendTo folder.

I created TestFile.txt file, which contains the words "Hello World". I placed the TestFile.txt file in TestFolder on my desktop.

I then performed the following two tests separately. Test #1: I right-clicked on TestFolder and clicked Send To > MyShortcut. Test #2: I dragged TestFolder onto MyShortcut on the desktop.

Here are the results of those two tests: nothing happened, except a window (which seemed to be some sort of DOS window) appeared for just a fraction of a second during each test. In other words, both tests failed.

By the way, I have never had any problem uploading stuff to the same FTP server using drag-and-drop in the WinSCP GUI.

The WinSCP folder contains the following files (in addition to the MyBatch.bat and example.txt files mentioned above): winscp418.exe and winscp418.ini. Could those names (which are the default names) be the cause of the problem? Should I change those names to winscp.exe and winscp.ini?

The WinSCP folder is at the following local location:

C:\Program Files\WinSCP

I am using WinSCP 4.1.8 (Build 415, "Portable executable") from the hard-drive on a Windows 2000 platform.

Re: Replace Existing Folder

Re: Replace Existing Folder

First, how would you map local directory path to remote directory path?
E.g. if you select local directory C:\aaa\bbb\ccc, how WinSCP can know corresponding remote directory?

WinSCP does not need to know anything about any local path. WinSCP simply needs to know the following: every time I use the right-click procedure (as described in my last post) to upload a folder, regardless of where that folder is located locally, WinSCP will automatically put that folder in "MyServerFolder". "MyServerFolder" is *not* just an example name. "MyServerFolder" is the actual name of an actual already-existing folder on the server, and that name "MyServerFolder" will never change. "MyServerFolder" will always be in the same location (root/MyServerFolder) on the server. "MyServerFolder" will never be deleted. "MyServerFolder" will always be only a *server* folder; there will never be a *local* folder named "MyServerFolder".

Andevorea

Re: Replace Existing Folder

2009-04-09 02:19

Here is what I want to want to be able to do: I sit down at my computer with WinSCP not yet opened. In Windows Explorer, I right-click on "XYZ" folder and click Send To > MyShortcut. Then all of the following happens automatically without any further clicks: WinSCP opens; WinSCP opens a connection to my FTP server; if "XYZ" folder already exists on the server in root/MyServerFolder, WinSCP changes the server "XYZ" folder to make it exactly the same as the local "XYZ" folder; if "XYZ" folder does not already exist on the server in root/MyServerFolder, WinSCP simply uploads "XYZ" folder to root/MyServerFolder; WinSCP closes the connection to my FTP server; WinSCP closes.

Notice in the edited version above, it says "Send To > MyShortcut" where it previously said "Send To > MyServerFolder". "MyShortcut" is a shortcut in the local Windows SendTo folder. "MyShortcut" is currently a dummy shortcut that does nothing. After you post instructions for me, I will configure the Properties of "MyShortcut" as you instruct me to configure it.

I never want to replicate any local path on the server. So regardless of where the local "XYZ" folder is located locally (C:\aaa\bbb\ccc\XYZ or C:\ddd\eee\fff\XYZ or C:\ggg\hhh\iii\XYZ or whatever), it will always be located on the server at root/MyServerFolder/XYZ.

I said above: if "XYZ" folder already exists on the server in root/MyServerFolder, WinSCP changes the server "XYZ" folder to make it exactly the same as the local "XYZ" folder. That means make the *contents* exactly the same as the local "XYZ" folder. That does not mean make the *path* the same as the local "XYZ" folder.

In the notes below, the phrase "right-click procedure" means the following procedure: In Windows Explorer, I right-click on "XYZ" folder and click Send To > MyShortcut.

"XYZ" is just an example name. The actual folder on which I do the right-click procedure may have any name at any given moment; in fact, it may be a name that WinSCP has not previously been "told" about.

"MyServerFolder" is *not* just an example name. "MyServerFolder" is the actual name of an actual already-existing folder on the server, and that name "MyServerFolder" will never change. "MyServerFolder" will always be in the same location (root/MyServerFolder) on the server. "MyServerFolder" will never be deleted. "MyServerFolder" will always be only a *server* folder; there will never be a *local* folder named "MyServerFolder".

I am using WinSCP 4.1.8 (Build 415, "Portable executable") from the hard-drive on a Windows 2000 platform.

Andevorea

Re: Replace Existing Folder

2009-04-09 02:15

Perhaps my last post was not clear enough. I will edit it to make it more clear and then post the edited version as a new post.

martin

Re: Replace Existing Folder

2009-04-08

First, how would you map local directory path to remote directory path?
E.g. if you select local directory C:\aaa\bbb\ccc, how WinSCP can know corresponding remote directory?

Andevorea

Re: Replace Existing Folder

2009-04-06 22:11

Thank you for your suggestion to use synchronization. After reading that suggestion, I read the help page about synchronization that you linked to and also some of your other help pages. After reading all of that stuff, I am quite impressed by the power and flexibility of WinSCP. But I am also kind of mystified because I am a WinSCP newbie.

Here is what I want to want to be able to do: I sit down at my computer with WinSCP not yet opened. In Windows Explorer, I right-click on "XYZ" folder and click Send To > MyServerFolder. Then all of the following happens automatically without any further clicks: WinSCP opens; WinSCP opens a connection to my FTP server; if "XYZ" folder already exists in root/MyServerFolder, WinSCP changes the server "XYZ" folder to make it exactly the same as the local "XYZ" folder; if "XYZ" folder does not already exist in root/MyServerFolder, WinSCP simply uploads "XYZ" folder to root/MyServerFolder; WinSCP closes the connection to my FTP server; WinSCP closes.

Please tell me how I can accomplish that.

By the way, "XYZ" is just an example folder name. The actual folder that I right-click on may have any name at any given moment; in fact, it may be a name that WinSCP has not previously been "told" about.

I am using WinSCP 4.1.8 (Build 415, "Portable executable") from the hard-drive on a Windows 2000 platform.

martin

Re: Replace Existing Folder

Re: Replace Existing Folder

2009-04-06 10:40

Yes, I can manually delete it first, and then upload the new version. But that is a two-step procedure for something that I want to do in just one step. If I only had to do that two-step procedure occasionally, it would be OK. But it is a procedure that I need to do constantly. So reducing it from two steps to one step would be very useful to me. It would save me a lot of time, and it would also help me avoid the mistake of forgeting to first delete the server folder. Is there any way that I can possibly accomplish this procedure in one step?

martin

Re: Replace Existing Folder

2009-04-06

So just delete it first, and upload the new version.

Andevorea

Replace Existing Folder

2009-04-04 12:35

When I upload "XYZ" folder, I want it to completely replace the "XYZ" folder that is already on the server. How can I accomplish that?