Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
1d6b1906
Commit
1d6b1906
authored
Sep 09, 2013
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added option to folllow symlinks to ftpfs, patch from Andrew
parent
7efa4873
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
10 deletions
+38
-10
fs/ftpfs.py
+27
-1
fs/opener.py
+1
-1
fs/tests/test_ftpfs.py
+10
-8
No files found.
fs/ftpfs.py
View file @
1d6b1906
...
@@ -337,6 +337,7 @@ class FTPListDataParser(object):
...
@@ -337,6 +337,7 @@ class FTPListDataParser(object):
i
=
0
i
=
0
while
(
i
+
3
)
<
len
(
result
.
name
):
while
(
i
+
3
)
<
len
(
result
.
name
):
if
result
.
name
[
i
:
i
+
4
]
==
' -> '
:
if
result
.
name
[
i
:
i
+
4
]
==
' -> '
:
result
.
target
=
result
.
name
[
i
+
4
:]
result
.
name
=
result
.
name
[:
i
]
result
.
name
=
result
.
name
[:
i
]
break
break
i
+=
1
i
+=
1
...
@@ -891,7 +892,7 @@ class FTPFS(FS):
...
@@ -891,7 +892,7 @@ class FTPFS(FS):
'file.read_and_write'
:
False
,
'file.read_and_write'
:
False
,
}
}
def
__init__
(
self
,
host
=
''
,
user
=
''
,
passwd
=
''
,
acct
=
''
,
timeout
=
_GLOBAL_DEFAULT_TIMEOUT
,
port
=
21
,
dircache
=
True
):
def
__init__
(
self
,
host
=
''
,
user
=
''
,
passwd
=
''
,
acct
=
''
,
timeout
=
_GLOBAL_DEFAULT_TIMEOUT
,
port
=
21
,
dircache
=
True
,
follow_symlinks
=
False
):
"""Connect to a FTP server.
"""Connect to a FTP server.
:param host: Host to connect to
:param host: Host to connect to
...
@@ -917,6 +918,7 @@ class FTPFS(FS):
...
@@ -917,6 +918,7 @@ class FTPFS(FS):
self
.
timeout
=
timeout
self
.
timeout
=
timeout
self
.
default_timeout
=
timeout
is
_GLOBAL_DEFAULT_TIMEOUT
self
.
default_timeout
=
timeout
is
_GLOBAL_DEFAULT_TIMEOUT
self
.
use_dircache
=
dircache
self
.
use_dircache
=
dircache
self
.
follow_symlinks
=
follow_symlinks
self
.
use_mlst
=
False
self
.
use_mlst
=
False
self
.
_lock
=
threading
.
RLock
()
self
.
_lock
=
threading
.
RLock
()
...
@@ -1018,6 +1020,30 @@ class FTPFS(FS):
...
@@ -1018,6 +1020,30 @@ class FTPFS(FS):
pass
pass
self
.
dircache
[
path
]
=
dirlist
self
.
dircache
[
path
]
=
dirlist
def
is_symlink
(
info
):
return
info
[
'try_retr'
]
and
info
[
'try_cwd'
]
and
info
.
has_key
(
'target'
)
def
resolve_symlink
(
linkpath
):
linkinfo
=
self
.
getinfo
(
linkpath
)
if
not
linkinfo
.
has_key
(
'resolved'
):
linkinfo
[
'resolved'
]
=
linkpath
if
is_symlink
(
linkinfo
):
target
=
linkinfo
[
'target'
]
base
,
fname
=
pathsplit
(
linkpath
)
return
resolve_symlink
(
pathjoin
(
base
,
target
))
else
:
return
linkinfo
if
self
.
follow_symlinks
:
for
name
in
dirlist
:
if
is_symlink
(
dirlist
[
name
]):
target
=
dirlist
[
name
][
'target'
]
linkinfo
=
resolve_symlink
(
pathjoin
(
path
,
target
))
for
key
in
linkinfo
:
if
key
!=
'name'
:
dirlist
[
name
][
key
]
=
linkinfo
[
key
]
del
dirlist
[
name
][
'target'
]
return
dirlist
return
dirlist
@synchronize
@synchronize
...
...
fs/opener.py
View file @
1d6b1906
...
@@ -434,7 +434,7 @@ examples:
...
@@ -434,7 +434,7 @@ examples:
dirpath
,
resourcepath
=
pathsplit
(
path
)
dirpath
,
resourcepath
=
pathsplit
(
path
)
url
=
netloc
url
=
netloc
ftpfs
=
FTPFS
(
url
,
user
=
username
or
''
,
passwd
=
password
or
''
)
ftpfs
=
FTPFS
(
url
,
user
=
username
or
''
,
passwd
=
password
or
''
,
follow_symlinks
=
(
fs_name_params
==
"symlinks"
)
)
ftpfs
.
cache_hint
(
True
)
ftpfs
.
cache_hint
(
True
)
if
create_dir
and
path
:
if
create_dir
and
path
:
...
...
fs/tests/test_ftpfs.py
View file @
1d6b1906
...
@@ -16,7 +16,9 @@ from six import PY3
...
@@ -16,7 +16,9 @@ from six import PY3
try
:
try
:
from
pyftpdlib
import
ftpserver
from
pyftpdlib.authorizers
import
DummyAuthorizer
from
pyftpdlib.handlers
import
FTPHandler
from
pyftpdlib.servers
import
FTPServer
except
ImportError
:
except
ImportError
:
if
not
PY3
:
if
not
PY3
:
raise
ImportError
(
"Requires pyftpdlib <http://code.google.com/p/pyftpdlib/>"
)
raise
ImportError
(
"Requires pyftpdlib <http://code.google.com/p/pyftpdlib/>"
)
...
@@ -89,21 +91,21 @@ if __name__ == "__main__":
...
@@ -89,21 +91,21 @@ if __name__ == "__main__":
# Run an ftp server that exposes a given directory
# Run an ftp server that exposes a given directory
import
sys
import
sys
authorizer
=
ftpserver
.
DummyAuthorizer
()
authorizer
=
DummyAuthorizer
()
authorizer
.
add_user
(
"user"
,
"12345"
,
sys
.
argv
[
1
],
perm
=
"elradfmw"
)
authorizer
.
add_user
(
"user"
,
"12345"
,
sys
.
argv
[
1
],
perm
=
"elradfmw"
)
authorizer
.
add_anonymous
(
sys
.
argv
[
1
])
authorizer
.
add_anonymous
(
sys
.
argv
[
1
])
def
nolog
(
*
args
):
#
def nolog(*args):
pass
#
pass
ftpserver
.
log
=
nolog
#
ftpserver.log = nolog
ftpserver
.
logline
=
nolog
#
ftpserver.logline = nolog
handler
=
ftpserver
.
FTPHandler
handler
=
FTPHandler
handler
.
authorizer
=
authorizer
handler
.
authorizer
=
authorizer
address
=
(
"127.0.0.1"
,
int
(
sys
.
argv
[
2
]))
address
=
(
"127.0.0.1"
,
int
(
sys
.
argv
[
2
]))
#print address
#print address
ftpd
=
ftpserver
.
FTPServer
(
address
,
handler
)
ftpd
=
FTPServer
(
address
,
handler
)
sys
.
stdout
.
write
(
'serving
\n
'
)
sys
.
stdout
.
write
(
'serving
\n
'
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment