EvilZone

Programming and Scripting => Scripting Languages => Topic started by: flowjob on December 17, 2011, 06:09:48 PM

Title: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 06:09:48 PM
Hi,
I want to make a little programm to enter a network and edit the files there.
I want to bind ftp to a new drive letter,but i didn't find a way to do this.I only found a way in cmd (net use) but it doesn't work.

Login into the ftp-sever does already work.But does one of you know a way to bind this to a new drive letter?

In advance:
I know there are a lot of programms,wich do this,but it's important to me to make it on my own!

sorry for my bad english.i'm still learning...

Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 06:14:21 PM
Hmm..

You are talking about virtually mapping a directory to a new drive letter. Not quite sure how to do it, but I am sure it is possible. But why not just use the folder you are mapping directly? Except for the cleanness, there is no advantage as far as I can see.

EDIT:
These are probably of interest:
http://www.codejacked.com/quick-tip-assign-a-drive-letter-to-a-folder-windows/
http://www.howtogeek.com/howto/windows-vista/map-a-drive-letter-to-a-folder-the-easy-way-in-windows/
Title: Re: [Python] Bind FTP to drive letter
Post by: iAmLuFFy on December 17, 2011, 06:15:16 PM
Hi,
I want to make a little programm to enter a network and edit the files there.
I want to bind ftp to a new drive letter,but i didn't find a way to do this.I only found a way in cmd (net use) but it doesn't work.

Login into the ftp-sever does already work.But does one of you know a way to bind this to a new drive letter?

In advance:
I know there are a lot of programms,wich do this,but it's important to me to make it on my own!

sorry for my bad english.i'm still learning...



Well you want to make a program.. can't help in it.
But if you are using windows then you can just map a folder which is on network and accessible as drive on your computer.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 06:26:23 PM
I've already seen the subst command,but how to use it for a directory on a ftp-server?

For example with this server and script:
(very simplified)

Code: (python) [Select]
#Python 2.7
import ftplib
ftp = ftplib.FTP('ftp.example.com')
ftp.login('myusername','mypassword')
ftp.pwd('example')

How to bind the directory 'example' to a drive letter with subst (or something better/else)?
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 06:29:20 PM
Are you asking how to navigate with the FTP protocol or if you can bind a directory to a drive letter with the FTP protocol? Because, you cannot do that with the FTP protocol. You need command access to do so.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 06:32:51 PM
I ask how to bind a directory of an ftp server to an drive letter.
I know how to navigate (ftp.cwd('directory'))
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 06:33:30 PM
I ask how to bind a directory of an ftp server to an drive letter.
I know how to navigate (ftp.cwd('directory'))


Ah, so you can use explorer to nav/open/edit/save etc?

If so, check FTP drive. Google it ;)
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 06:36:03 PM
I never used the explorer.I have always been navigating with ftp.cwd('directory')
But i want to know how to do it with explorer with binding the ftp-server to a new drive letter.


And I want to make it ON MY OWN.
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 06:38:30 PM
I never used the explorer.I have always been navigating with ftp.cwd('directory')
But i want to know how to do it with explorer with binding the ftp-server to a new drive letter.

Yes, just told you. Use FTP Drive(simple software for windows) and map it to a drive. BAM, you can now use your explorer as FTP navigator.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 06:40:51 PM
As you can read in my upper post I know that there are a lot of programs for this,but i want to MAKE IT ON MY OWN
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 06:47:25 PM
As you can read in my upper post I know that there are a lot of programs for this,but i want to MAKE IT ON MY OWN

Seams kinda pointless, if there is an existing solution to a problem. Use it. But ohwell. You would need to look into virtual drives then, and python would probably not be your best choice of language. I am thinking C or C++. You probably need to do some kernel hooking maybe. Dunno really, haven't done something like this before.

Nonetheless. What you need to do is make your program and Explorer communicate whenever Explorer accesses the desired drive path, then do whatever Explorer want (open, edit, delete, rename, move) and do the appropriate actions within your program and return the expected result back to Explorer.

My money would be on hooking some directory listing kernel function and then manipulate the results when the desired path is used. There might be some API for this too tho.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 08:29:46 PM
I had an idea,but it doesn't work:

Code: (python) [Select]
#Python 2.7
import os
import ftplib
ftp = ftplib.FTP('ftp.example.com')
ftp.login('myusername','mypassword')
ftp.pwd('example')
os.system('subst V: ' + ftp.pwd())

Error:
Invalid parameter - /

Because the working directory is '/', and subst needs a drive letter at the beginning of the directory.

Does one know a solution?
Or is it impossible this way (because the server OS is Unix)?
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 08:59:26 PM
I had an idea,but it doesn't work:

#Python 2.7
import os
import ftplib
ftp = ftplib.FTP('ftp.example.com')
ftp.login('myusername','mypassword')
ftp.pwd('example')
os.system('subst V: ' + ftp.pwd())

Error:
Invalid parameter - /

Because the working directory is '/', and subst needs a drive letter at the beginning of the directory.

Does one know a solution?
Or is it impossible this way (because the server OS is Unix)?

It wont work like that, and because there exist FTP servers for all OS's. This is not impossible. However, you cant expect it to work directly like that. You need a translator between the drive and Explorer. Like I said, I don't know if Python is the best suitable language for this.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 09:15:44 PM
I'm sure it's not the best,but the only one I can program (except batch)

That there exist FTP Server for all OS isn't a problem,because i make it for my schoolnetwork,and there's UNIX the OS of the server.

What do you mean with I need a translator between the drive and the explorer?
(I'm just a beginner at network-programming)
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 09:30:00 PM
I'm sure it's not the best,but the only one I can program (except batch)

That there exist FTP Server for all OS isn't a problem,because i make it for my schoolnetwork,and there's UNIX the OS of the server.

What do you mean with I need a translator between the drive and the explorer?
(I'm just a beginner at network-programming)


I mean there have to be someone in the middle between Explorer and the FTP server. As Explorer doesn't know FTP. Like this:
Explorer <-> Your program <-> FTP server

EDIT:
Ohwait, I just found this: http://cybernetnews.com/cybernotes-map-a-ftp-to-a-drive-in-windows/
So Explorer does know FTP. But I am not quite sure how to do this programmatically, but I am sure it is possible by some registery manipulation and so forth.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 09:52:51 PM
But can this work

Code: [Select]
os.system('subst V: ' + ftp.pwd())
If the server is Unix?
Because subst requires a drive letter at the beginning...

I don't know Unix,but they have no drive letter,have they?
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 10:09:00 PM
But can this work

os.system('subst V: ' + ftp.pwd())

If the server is Unix?
Because subst requires a drive letter at the beginning...

I don't know Unix,but they have no drive letter,have they?

That is not going to work at all. ftp.pwd() is not a valid resource to pass to subst, subst takes a URL or server address, not an FTP object or any other object or resource.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 10:12:03 PM
How could I bind it with subst and the url ftp.example.com if it needs a password?
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 10:16:07 PM
How could I bind it with subst and the url ftp.example.com if it needs a password?

I am not sure that is possible. But you could always try the user:pass@ftp.example.com trick. ftp://username:password@ftp.example.com will(should) automatically log you in upon opening. (It might have been disabled in later versions of windows tho, I recall reading something about that somewhere.)
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 10:28:44 PM
subst V: ftp://myusrname:mypass@ftp.example.com doesn't work
 (names changed)
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 10:31:13 PM
Then subst does not support FTP. Check the URL I posted about mapping a FTP to explorer manually. I am sure you can do it programmatically if you do some research.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 10:34:30 PM
It works now!

I start ftp://unsrname:pass@ftp.example.com with the browser

@ande:
thx,for the help

Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 10:42:40 PM
But it's just a temporary solution.I'm still searching for a way to bind it to a drive letter,because it looks more professional.If someone finds a way (with python/batch) please post it.

Is there a way to say cmd ftp://... is on the internet and no local path?
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 10:53:03 PM
Is there a way to say cmd ftp://... is on the internet and no local path?

Could you rephrase that?
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 17, 2011, 11:16:02 PM
Forget that,I wrote it without thinking before...

But is there a way to bind the FTP to a drive letter,and open it with the Fileexplorer instead of open it with the browser?

Tried it with 'net use' and 'subst' with the direct url and with a urllink on my Computer...
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 17, 2011, 11:43:11 PM
Forget that,I wrote it without thinking before...

But is there a way to bind the FTP to a drive letter,and open it with the Fileexplorer instead of open it with the browser?

Tried it with 'net use' and 'subst' with the direct url and with a urllink on my Computer...

I believe that is what we have discussed the past 10 posts :P There is, manually( check the link I posted ). Programmatically, on the other hand, I dunno. But I am sure it can be done by registery and maybe some command line stuff.

Guess we gotta wait for some other guys to answer that, or you have to do the research/testing yourself.
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 18, 2011, 03:50:52 PM
Ok, I tried something and made it to open the FTP with Fileexplorer.
But how can I tell the computer to open the url ftp://usrname:pass@ftp.example.com with File Explorer instead of Internet Explorer/Firefox/etc (wich is automatically used to open it) ?
Title: Re: [Python] Bind FTP to drive letter
Post by: ande on December 18, 2011, 04:52:48 PM
Ok, I tried something and made it to open the FTP with Fileexplorer.
But how can I tell the computer to open the url ftp://usrname:pass@ftp.example.com with File Explorer instead of Internet Explorer/Firefox/etc (wich is automatically used to open it) ?

You write it in the address-bar? :P If you want to start it from command line, you can probably do something like "explorer ftp://usrname:pass@ftp.example.com"
Title: Re: [Python] Bind FTP to drive letter
Post by: flowjob on December 18, 2011, 04:58:39 PM
works,thx
Title: Re: [Python] Bind FTP to drive letter
Post by: Stackprotector on December 23, 2011, 12:28:45 AM
What about creating your own little system inspired on filesystems based on dropbox and tortoiseSVN,  they give the right mouse click extra functions, and show you what files are changed since last upload to server etc..