Replace Existing Folder

Advertisement

Andevorea
Guest

Replace Existing Folder

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?

Reply with quote

Advertisement

Andevorea
Guest

Re: Replace Existing Folder

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?

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

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.

Reply with quote

Advertisement

martin
Site Admin
martin avatar

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?

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

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.

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

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.

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

martin wrote:

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".

Reply with quote

Advertisement

Andevorea_
Guest

Re: Replace Existing Folder

martin wrote:

I have added some example to useful script article. Let me know if it helps.

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 example.txt file, which contains the following code:

# Being intended for interactive session, we are not enabling batch mode
# Connect
open session
# Synchronize paths provided via environment variables
synchronize remote %LOCAL% %REMOTE%

I placed the example.txt file in my WinSCP 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.

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

martin wrote:

Well you need to replace "session" in "open session" with some real session.

I did the replacement you suggested. Here is the new code:

# Being intended for interactive session, we are not enabling batch mode
# Connect
open username@example.com
# Synchronize paths provided via environment variables
synchronize remote %LOCAL% %REMOTE%

(The username and domain name are changed here for privacy.)

It still has exactly the same problem that I described in my last post.

Reply with quote

Advertisement

Andevorea
Guest

Re: Replace Existing Folder

martin wrote:

Try to execute the batch file from command line to see what it outputs.

Martin, please forgive my ignorance, but I do not know how to execute the batch file from command line. Please tell me exactly to do that.

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

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:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>"C:\Program Files\WinSCP\MyBatch.bat"

C:\>set LOCAL=

C:\>set REMOTE="/MyServerFolder/"

C:\>winscp.com /script=example.txt
'winscp.com' is not recognized as an internal or external command,
operable program or batch file.

C:\>

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

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.

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Replace Existing Folder

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.

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

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

Reply with quote

Andevorea
Guest

Re: Replace Existing Folder

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".

Reply with quote

martin
Site Admin
martin avatar

Re: Replace Existing Folder

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.

Reply with quote

Advertisement

Andevorea
Joined:
Posts:
6

Re: Replace Existing Folder

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.

Reply with quote

martin
Site Admin
martin avatar

Re: Replace Existing Folder

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"
Last edited by martin on 2009-04-22; edited 1 time in total

Reply with quote

Andevorea
Joined:
Posts:
6

Re: Replace Existing Folder

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?

Reply with quote

martin
Site Admin
martin avatar

Re: Replace Existing Folder

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.

Reply with quote

Advertisement

Andevorea
Joined:
Posts:
6

Re: Replace Existing Folder

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.

Reply with quote

martin
Site Admin
martin avatar

Re: Replace Existing Folder

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.

Reply with quote

Andevorea
Joined:
Posts:
6

Re: Replace Existing Folder

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.

Reply with quote

Andevorea
Joined:
Posts:
6

Re: Replace Existing Folder

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.

Reply with quote

Advertisement

Andevorea
Joined:
Posts:
6

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%

Reply with quote

Advertisement

You can post new topics in this forum