Virtual File System with FTP - python

I've been reading through the FileSystem documentation in Python from here:
http://packages.python.org/fs/filesystems.html
After taking the time to read through it and a bit of Google-ing I didn't quite find the answer I was looking for. I was wondering if it was possible with Python, and avoiding any UAC issues on Windows, if you could 'mount' or display a file free from an FTP server inside Windows Explorer for any other applications to -read- from.
Is something this possible? What's the best approach to achieve it? Thanks in advance!

Windows explorer has built-in support for FTP, instructions with screenshots here.
Open Windows Explorer (My computer)
Right-click anywhere in the folder, and then click Add a Network Location.
This displays the Add Network Connection wizard. Click Next.
In the wizard, select Choose a custom network location, and then click Next.
Enter the name of the FTP site, with the full FTP:// in front of it, and then click Next (something like - for example if you domain name is DOMAIN.NET the full name should look like this: ).
To use a name and password, clear the Log on anonymously check box. Type your FTP Account Username, and then click Next.
By default, the name of the shortcut is the same as the FTP address. If you want to give the shortcut a different name, type it in the Type a name for this network location box. Click Next.
You can even use it from the standard "file" dialog box. Is it enough?
[update]
Out of curiosity, does this have support for FTPS and/or SFTP? – André Caron
#AndréCaron: I think WebDAV with SSL is supported, but no native support for SFTP or FTPS. There are extensions like Swish (opensource) or Expandrive (payware).

This is a non-trivial matter and afaik there exist not such a thing as provide os-level functionality through some lines of magical python code.
A possible solution to emulate your intention could be to create a local webdav proxy, which maps to the ftp-server. I know there exists a feature to attach a webdav-network device to a local drive-letter, but because the last time i touched a windows system was ... - i can't even remember - i can't tell you if you might also attach a ftp-resource this way directly.
I guess looking for a solution on a python level might not be productive in a short-term perspective and even on mid/long-term's not possible without heavy tinkering on your side.

While not a "filesystem" per-se, you can provide a Windows Explorer Namespace Extension which will allow the Windows explorer to browse any virtual file-system. This is used to implement browsing of ZIP archives, for example. Note that this does not provide a real file system drive, so it will not allow you to open the contents of this namespace extension using regular file I/O functions.
The namespace extensions are written in COM, and it is possible to implement COM interfaces in Python.
AFAIK, the only permissions you need are for installing of the namespace extension (the COM DLL, plus the namespace registration). Everything else runs in the logged-in user's context and requires no special permissions.

Related

How to find if a network interface is using dhcp/static ip without relying on sh (e.g. `ip route`) using python?

I currently need to find out if any network interface (on RHEL) is configured to use dynamic IP (DHCP) using python (python2 preferably, but if there's a solution using python3, I'd like to hear it).
I don't want to throw a bash subprocess and just parse the response from ip route or nmcli for instance.
What we tried/found out so far:
There's a python lib (currently archived) netifaces but even with that we were not able to make it give us that answer. Also having second thoughts of depending on a lib that has been archived a while ago.
On /sys/class/net it's possible to see the interfaces and on it there are a lot of properties, but none of it seems to give what we want. Maybe there's another Linux interface that could give us that?!
On /etc/sysconfig/network-scripts/ifcfg-** it's possible to see options of every interface (NetworkManager is the owner I guess) and one could parse the BOOTPROTO= option. However, that does not necessarily show the current connection method because one could change that file or even modify the interface through nmcli and that would only be read after the interface has been restarted (down/up)
Note: Sorry if some specific network terms were not correctly used, I'm not an expert there :)
Any thoughts? Any ideas?

Does xlwings only work with the first instance of Excel?

Is this a known limitation that will be addressed at some point, or is this just something that I need to accept?
If this is not possible with xlwings, I wonder if any of the other alternatives out there supports connecting to other instances.
I'm specifically talking about the scenario where you are calling python from within Excel, so the hope is that the getCaller() function will be able to figure out which instance of the Excel is actually calling it.
Ok, based on your comments I think I can answer your question: Actually, yes, xlwings can handle various instances. But workbooks from untrusted locations (like downloaded from the internet or sometimes on shared network drives) don't play nicely.
So in your case you could try to add the network location to File > Options > Trust Center > Trust Center Settings... > Trusted Locations or, under Trusted Documents, tick the checkbox Allow documents on a network to be trusted.
If you don't have the previlegies to change these options, then I guess you're left with the options of running the tools locally or indeed, open them in the 1st instance...

is there a module that enables property editing for general windows files

so recently, a technologically clever fellow hid all the files in my school's most frequently accessed and most important public networked mounted drives.
now, as the problem hasn't yet been fixed, i see it as an opportunity to expand my knowledge on python. I would like if there is a module that allows me to edit the properties of files in folders in general. !!EDIT: Windows folders.
not the /contents/, the properties. like the date/time accessed, images of mp3 music, and more importantly, the hidden/not hidden status of files.
You can use the Python for Windows package to access a wide range of Windows API's. In particular, the SetFileAttributes function will be useful. You can see an example here. There are other API's such as GetFileAttributes and GetFileAttributesEx to can use to get more information. they'll be defined in the same place as SetFileAttributes.

I want to setup and manage my own local 'autocomplete', so I can fill in the correct box with a password

It seems like passwords are always getting compromised. I want to write a program, preferably in C/C++ or Python, that I can use to fill in my passwords on the various sites I visit but do so from a program I manage on my machine that stores my pws and logins locally.
The reason a program is the best idea would be so that I can make very strong passwords and change them often. I would be able to choose my own encryption for the local storage/database. I would also be able to manage a schedule to keep passwords young.
I am asking the question because I haven't had much luck looking for a starting point. For instance, can I use Python to ask my browser for a list textboxes on a page I have open in a browser? Can I fill in the text boxes and click buttons from code that runs independent of the browser?
It didn't look like Google Python API was right, and I don't know that JS would act like a console app. Maybe Selenium and Python?
A good answer for me would be languages and platforms that would meet these requirements. I'm open to learning a new language or using a different browser, but I have no idea where to start.
Thanks in advance!
Although there are ways to control your browser from a local Python/C/C++ application (see mechanize, from insepctorG4dget's comment), you would have a much easier time with an extension.
First of all, you wouldn't have to use some roundabout route, and instead, you could use well documented APIs. I'm not sure about other browsers, but I know that Chrome and Firefox both would be easy to make this in.
For storage, Chrome has the filesystem API and Firefox has the file API. Chrome also has the chrome.storage API, and if you use Chrome Sync, this could come in handy.
Extensions are made in HTML/CSS/JS, but the amount of HTML and CSS required for the type of extension you're looking for is a piece of cake, and if you're familiar with both Python and C, JS would be quite simple to pick up. You could also use a language that compiles to Javascript- there are tons out their.
There are plenty of libraries that would make your task easier in JavaScript than in some other library- for DOM access, of course, their's JQuery, and for encryption, there's sjcl. If you want a random password generator, of course, you could just use Math.random, in the core/built-in JS library.
Security
If someone wanted to steal your password from your local computer, a local application may be easier to steal from, as all the data is stored locally (although if it is encrypted, this wouldn't be so much of a problem). Locally stored passwords would be extremely hard to hack from externally, because the hackers would have to know exactly how your extension was implemented, and find some bug to exploit- near impossible if you do a decent job.
If you use Chrome's autocomplete, then it should be pretty secure from hackers- a popular browser like Chrome would have to be secure, but I have no idea how it was implemented, so you should probably double check on this. Just remember though, all of your passwords are being sent to advertisers and the NSA. ;)
An extension probably would be the least secure, since it may be vulnerable to both external and local attacks. However, again, either a local program, or an extension, you don't need worry unless:
You're doing something "Quick and Dirty"
You're not encrypting it
Some major organization with professional hackers wants all of your personal information

Secure plugin system for python application

I have an application written in python. I created a plugin system for the application that uses egg files. Egg files contain compiled python files and can be easily decompiled and used to hack the application. Is there a way to secure this system? I'd like to use digital signature for this - sign these egg files and check the signature before loading such egg file. Is there a way to do this programmatically from python? Maybe using winapi?
Is there a way to secure this system?
The answer is "that depends".
The two questions you should ask is "what are people supposed to be able to do" and "what are people able to do (for a given implementation)". If there exists an implementation where the latter is a subset of the former, the system can be secured.
One of my friend is working on a programming competition judge: a program which runs a user-submitted program on some test data and compares its output to a reference output. That's damn hard to secure: you want to run other peoples' code, but you don't want to let them run arbitrary code. Is your scenario somewhat similar to this? Then the answer is "it's difficult".
Do you want users to download untrustworthy code from the web and run it with some assurance that it won't hose their machine? Then look at various web languages. One solution is not offering access to system calls (JavaScript) or offering limited access to certain potentially dangerous calls (Java's SecurityManager). None of them can be done in python as far as I'm aware, but you can always hack the interpreter and disallow the loading of external modules not on some whitelist. This is probably error-prone.
Do you want users to write plugins, and not be able to tinker with what the main body of code in your application does? Consider that users can decompile .pyc files and modify them. Assume that those running your code can always modify it, and consider the gold-farming bots for WoW.
One Linux-only solution, similar to the sandboxed web-ish model, is to use AppArmor, which limits which files your app can access and which system calls it can make. This might be a feasible solution, but I don't know much about it so I can't give you advice other than "investigate".
If all you worry about is evil people modifying code while it's in transit in the intertubes, standard cryptographic solutions exist (SSL). If you want to only load signed plugins (because you want to control what the users do?), signing code sounds like the right solution (but beware of crafty users or evil people who edit the .pyc files and disables the is-it-signed check).
Maybe some crypto library like this http://chandlerproject.org/Projects/MeTooCrypto helps to build an ad-hoc solution. Example usage: http://tdilshod.livejournal.com/38040.html

Categories