Can I configure a WinSCP instance to always run in the background, keeping a remote directory up to date? - background

I like using WinSCP for keeping a remote directory up to date, but it locks up the rest of the interface while in use. Is there any way I can configure WinSCP to run on startup (in the background) and keep a certain remote directory up to date with a local copy without impacting the rest of WinSCP's interface?

You can run two instances of WinSCP. One for keeping remote directory up to date, the other for an interactive use.
You can have WinSCP automatically start keeping remote directory up to date. There are two ways, GUI mode and scripting.
GUI mode:
C:\path_to_winscp\WinSCP.exe session_name /defaults
/keepuptodate // C:\local_path /remote_path
(Line break added for readability. The /defaults make WinSCP skip the options dialog.)
For details, see https://winscp.net/eng/docs/commandline
This way you cannot make WinSCP open in the background. You have to manually press the Minimize button.
Scripting mode:
C:\path_to_winscp\WinSCP.exe /console /command "option batch abort"
"open session_name" "keepuptodate C:\local_path /remote_path"
(Line break added for readability.)
For details, see https://winscp.net/eng/docs/guide_automation
If you store this command to a shortcut, you can set it's Run property to Minimized.
For both modes, you can store the command to a shortcut and move it to C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup to have it automatically started with Windows.
Minimizing to a tray:
Minimizing to a tray is a global preference option:
https://winscp.net/eng/docs/ui_pref_window
If you do not want to enable it globally (it would apply even to the WinSCP instance for an interactive use), add this to the command-line:
/rawconfig Interface\MinimizeToTray=1
See Raw configuration.

Related

How to run a script from startup on Raspbian 10 (buster)?

I have designed a GUI that I want to run as soon as I turn on my Raspberry Pi. It is currently set up to automatically log in as user on startup, but if that makes the process more difficult I can change that. My Raspi runs on Raspbian 10 (buster), which has made things difficult since I can only find tutorials for Raspbian 8 or so.
I have tried modifying autostart folder, but it is not in the same location as it was in previous Raspbian versions and doesn't seem to be working the way it used to. Tutorials have said to create a .desktop file in /home/pi/.config/autostart but I don't have a .config folder, or at least it's hidden. For me, autostart is in /etc/xdg/autostart and when I try to create a new file here using nano in the terminal, I get the message [Directory '/etc/xdg/autostart' is not writable] and it doesn't save my file.
I have also tried calling my script in /etc/rc.local but it did nothing. Some have said it doesn't work for GUIs.
Here's what I type into terminal:
$ nano /etc/xdg/autostart/gui.desktop
and a new file pops up, but at the bottom I get the warning [Directory '/etc/xdg/autostart' is not writable]
How can I get my GUI script to run on startup with Raspbian 10 (buster)?
There are a number of issues here, first when you are looking at tutorials recognize that Linux distros are built in layers, for simplicity let's say your "layer stack" looks like this: kernel, systemd, x11, xdg, lxde. The kernel boots, then starts systemd, which then starts x11 (and a lot of other stuff), x11 starts xdg (and some other stuff, I think), lxde is started by either x11 or xdg I'm not sure which.
You want to add something to this process, you can do it at the kernel level (bad idea), at they systemd level (probably not right unless its a daemon), at the x11 level (still probably bad as you still don't have a user session yet), or at the xdg or lxde level.
xdg is probably the right place as it has all you need ( a gui, a user session) while being common (xdg will still work if you switch window managers, probably)
With that out of the way, why isn't your solution of modifying xdg working? It's because '/etc/xdg/autostart' is a system configuration directory. Any changes made to it will apply to all users. You may want this, but the system is trying to protect other users on your system and only allows root to make changes to everyone. If you want to do that use "sudo" (documented elsewhere on stack exchange and the internet). If you want to do it just for you use ~/.config/autostart, (https://wiki.archlinux.org/index.php/XDG_Autostart) you might need to create that directory with "mkdir ~/.config/" and then "emacs ~/.config/autostart"
Would it be better to have the python program run in a terminal window from startup? That way you would see what it is doing in case of errors.
If so, perhaps check this out https://stackoverflow.com/a/61730679/7575617
By the way, in the file manager, hit CTRL+H to toggle viewing hidden files and folders.

Change putty settings using scripts

Is there any way to save the PuTTY output to a file using the command line? I know this is easily done using the GUI but in my case it has to be done automatically.
What I'm working on:
User clicks batch file -> starts PuTTY, automatically connects to my device over SSH and runs a bunch of commands -> PuTTY should save the output to a file.
This can be done by changing registry settings.
Entry point for you is to check what and where is stored for putty:
run regedit and go to HKEY_CURRENT_USER\Software\SimonTatham\PuTTY
you can export settings to file by:
regedit /e "%userprofile%\desktop\putty-registry.reg" HKEY_CURRENT_USER\Software\Simontatham
From here,edit putty-registry.reg to your needs and import on user machine.

Using WinSCP script for SFTP access from SSIS

I am new to WinSCP and am attempting to create a script file that will eventually be used with SSIS to download files from an SFTP site. A lot of the literature WinSCP includes explains the file downloading or uploading portions. For the time being, I just want to create a script to test the connection first and will build from there.
So far I saved the connection in WinSCP and have the following. The below code does not seem to function at all and I am not sure where else to go as I am still reading about the scripting for WinSCP. Is there a way or can someone point me in a direction to see if I am in fact connecting via through the script?
option batch on
option confirm off
open username#address
exit
Not sure what SSIS is (sorry) but I can tell you how I'd set it up from a windows batch file if that helps:
If you are open to using a different software, consider using cygwin. It mimics a linux shell so linux users on windows have a lot of linux utilities handy. That being said, there are some commands which can run on windows straight from command prompt (and thus batchable). What you'd need to do:
1) install cygwin
2) Create a "passwordless" login (using ssh-rsa authentication). To do this start your cygwin terminal and use the commands "ssh-keygen" and "ssh-copy-id" (more on that later)
3) Now you can run "sftp" from the DOS command prompt (does not require cygwin terminal) and sftp to your account. No password required because of step 2).
A few follow up info:
What can run from dos command prompt and what must be run from cygwin terminal?
If you go to the "bin" directory of cygwin (for me it's in c:\cygwin\bin) you can see all the cygwin utilities. Anything with "exe" extension can be run from dos command prompt. If no "exe" extension, must start cygwin terminal first
How to set up ssh-rsa authentication?
You can pretty much google "ssh login without password" and pull up a lot of results. This is common for setting up login from one linux system to another. You would be using the same steps using cygwin on windows. My instructions are here:
http://geekswing.com/geek/unix/how-to-ssh-login-without-a-password-using-ssh-keygen-quick-tutorial/
Storing session settings in WinSCP GUI and trying to access them from WinSCP script running in SSIS is generally a bad idea. I believe there's no example or guide on WinSCP site that would suggest doing that.
WinSCP stores its configuration in registry in HKEY_CURRENT_USER hive. The SSIS typically runs under a dedicated system account, that have its own HKEY_CURRENT_USER hive, and won't see the GUI configuration.
For details see WinSCP FAQ about your problem:
https://winscp.net/eng/docs/faq_scheduler
The best you can do is isolate your your script from configuration by using the session URL with the open command, instead of the stored site name.
See also https://winscp.net/eng/docs/scripting#configuration
Your actual problem can be completely different though. But that's hard to guess as you have not shared any details, such as error message, log file, etc.

Detect file in use by other process

On windows and such I used to use a trick to find out of a file is currently in use (written specifically).
I use to open the file for writing and if it failed most likey another process is busy accessing it.
Sadly these trick (using C OPEN with exclusive lock for writing) doesn't work on my Mac. While my curl in a terminal is still writing my -fileBusy() check fails.
fcnt call on the fd with F_GETLK doesn't reveal any locking as well.
Is there any chance for me to detect if a file is in use by another process?
Ps> listening for fsevents can't be done because my app launches after the is created by the other app / process.
Apple confirmed via email that the solution described in the link below is a valid one and not considered a private API.
More information:
http://lists.apple.com/archives/cocoa-dev/2010/May/msg01455.html
You could try running the following shell command using NSTask:
lsof -Fc path/to/thefile
That will give you the process ID and name of any process(es) that have thefile open.

controlling lauterbach through command line

I have condition that i have to flash multiple output files one by one to the mpc controller. We use GUI for lauterbach to do the flashing and running software. Now i want to do the same via >command line argument. Some one please explain me what all things are needed for controlling the lauterbach through command prompt.
I want to use Lauterbach Powerdebug interface/ usb2 for the debugging purpose.
You can remote-control trace32 via a UDP port using the t32rem command.
t32rem is typically installed in C:\T32\bin\windows64\
Your t32 configuration file (config.t32) must have "RCL=NETASSIST" in it.
And you need to enable the API port, either via the t32start options or in your custom xxx.ts2 (configuration file).
Out of the box you should then be able to run any t32 command. E.g.:
C:\T32\bin\windows64\t32rem.exe localhost port=20000 data.dump 100000
Replace "data.dump 100000" with anything T32 understands, e.g. "do pgm_my_flash.cmm"
You can also use telnet to remote control the debugger. NETASSIST must be set.