-
Andevorea
Guest
Replace Existing Folder
Advertisement
Advertisement
-
martin◆
Site Admin - Joined:
- Posts:
- 41,518
- Location:
- Prague, Czechia
Re: Replace Existing Folder
-
Andevorea
Guest
Re: Replace Existing Folder
-
martin◆
Site Admin
Re: Replace Existing Folder
-
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 > 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.
Advertisement
-
martin◆
Site Admin
Re: Replace Existing Folder
E.g. if you select local directory C:\aaa\bbb\ccc, how WinSCP can know corresponding remote directory?
-
Andevorea
Guest
Re: Replace Existing Folder
-
Andevorea
Guest
Re: Replace Existing Folder
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
Guest
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".
Advertisement
-
martin◆
Site Admin
Re: Replace Existing Folder
-
Andevorea_
Guest
Re: Replace Existing Folder
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.
-
martin◆
Site Admin
Re: Replace Existing Folder
-
Andevorea
Guest
Re: Replace Existing Folder
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.
Advertisement
-
martin◆
Site Admin
Re: Replace Existing Folder
-
Andevorea
Guest
Re: Replace Existing Folder
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.
-
Andevorea
Guest
Re: Replace Existing Folder
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:\>
-
Andevorea
Guest
Re: Replace Existing Folder
Advertisement
-
martin◆
Site Admin
Re: Replace Existing Folder
-
Andevorea
Guest
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.
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
-
Andevorea
Guest
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.
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".
-
martin◆
Site Admin
Re: Replace Existing Folder
Advertisement
- Andevorea
- Joined:
- Posts:
- 6
Re: Replace Existing Folder
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◆
Site Admin
Re: Replace Existing Folder
- Andevorea
- Joined:
- Posts:
- 6
Re: Replace Existing Folder
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◆
Site Admin
Re: Replace Existing Folder
OK, correct. Fixed.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?
Advertisement
- Andevorea
- Joined:
- Posts:
- 6
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"
I would prefer to have only one shortcut, which will be used in all situations. Please post the "complicated scripting" code.
-
martin◆
Site Admin
Re: Replace Existing Folder
It would take some time. May do once. Cannot promise.I would prefer to have only one shortcut, which will be used in all situations. Please post the "complicated scripting" code.
- Andevorea
- Joined:
- Posts:
- 6
Re: Replace Existing Folder
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.
- 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.
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.
Advertisement
- Andevorea
- Joined:
- Posts:
- 6
Re: Replace Existing Folder
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%
-
martin◆
Site Admin - Joined:
- Posts:
- 41,518
- Location:
- Prague, Czechia
Re: Replace Existing Folder
Are you sure you have stored session named "session"?open session
Otherwise, please read how to troubleshoot problems with WinSCP. If it turns out that you are not able to help yourself, read how to ask for support or report bugs efficiently, so others can help you.
Advertisement
You can post new topics in this forum