Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
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
ops
coco
Commits
278a4200
Commit
278a4200
authored
Sep 28, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 不支持复制文件夹
parent
f5879bce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
connector.py
coco/httpd/elfinder/connector.py
+3
-0
sftp.py
coco/httpd/elfinder/volumes/sftp.py
+26
-1
sftp.py
coco/sftp.py
+1
-1
No files found.
coco/httpd/elfinder/connector.py
View file @
278a4200
...
...
@@ -269,6 +269,7 @@ class ElFinderConnector:
def
__upload
(
self
):
parent
=
self
.
data
[
'target'
]
volume
=
self
.
get_volume
(
parent
)
upload
=
self
.
data
.
get
(
'upload[]'
)
if
self
.
data
.
get
(
'chunk'
)
and
self
.
data
.
get
(
'cid'
):
self
.
response
.
update
(
volume
.
upload_as_chunk
(
...
...
@@ -279,6 +280,8 @@ class ElFinderConnector:
self
.
response
.
update
(
volume
.
upload_chunk_merge
(
parent
,
self
.
data
.
get
(
'chunk'
))
)
elif
isinstance
(
upload
,
str
):
self
.
response
.
update
(
volume
.
upload_as_url
(
upload
,
parent
))
else
:
self
.
response
.
update
(
volume
.
upload
(
self
.
request
.
files
,
parent
))
...
...
coco/httpd/elfinder/volumes/sftp.py
View file @
278a4200
import
stat
import
threading
import
tempfile
from
flask
import
send_file
import
requests
from
coco.utils
import
get_logger
from
.base
import
BaseVolume
...
...
@@ -87,7 +89,7 @@ class SFTPVolume(BaseVolume):
def
list
(
self
,
target
,
name_only
=
False
):
""" Returns a list of files/directories in the target directory. """
path
=
self
.
_path
(
target
)
# print("List {}-
{}".format(target, path))
print
(
"List {}
{}"
.
format
(
target
,
path
))
with
self
.
lock
:
return
self
.
_list
(
path
)
...
...
@@ -106,6 +108,7 @@ class SFTPVolume(BaseVolume):
获取目录的父目录, 如果deep为0,则直到根
"""
path
=
self
.
_path
(
target
)
.
rstrip
(
self
.
path_sep
)
print
(
"Parents {} {}"
.
format
(
target
,
path
))
with
self
.
lock
:
return
self
.
_parents
(
path
,
depth
=
depth
)
...
...
@@ -177,6 +180,13 @@ class SFTPVolume(BaseVolume):
exist
=
False
return
exist
def
is_dir
(
self
,
path
):
info
=
self
.
_info
(
path
)
if
info
[
'mime'
]
==
'directory'
:
return
True
else
:
return
False
def
paste
(
self
,
targets
,
dest
,
cut
):
""" Moves/copies target files/directories from source to dest. """
print
(
"Paste {} {} {}"
.
format
(
targets
,
dest
,
cut
))
...
...
@@ -187,6 +197,8 @@ class SFTPVolume(BaseVolume):
for
target
in
targets
:
src_path
=
self
.
_path
(
target
)
dest_path
=
self
.
_join
(
dest_parent_path
,
self
.
_base_name
(
src_path
))
if
self
.
is_dir
(
src_path
):
raise
OSError
(
"Copy folder unsupported now"
)
print
(
"Paste {} to => {}"
.
format
(
src_path
,
dest_parent_path
))
if
self
.
is_exist
(
dest_path
):
print
(
"Exist {}"
.
format
(
dest_path
))
...
...
@@ -218,6 +230,19 @@ class SFTPVolume(BaseVolume):
raise
OSError
(
"Delete {} failed"
.
format
(
self
.
_base_name
(
path
)))
return
target
def
upload_as_url
(
self
,
url
,
parent
):
added
=
[]
parent_path
=
self
.
_path
(
parent
)
path
=
self
.
_join
(
parent_path
,
self
.
_base_name
(
url
))
remote_path
=
self
.
_remote_path
(
path
)
r
=
requests
.
get
(
url
,
stream
=
True
)
with
self
.
sftp
.
open
(
remote_path
,
'w'
)
as
rf
:
for
chunk
in
r
.
iter_content
(
chunk_size
=
1024
):
if
chunk
:
# filter out keep-alive new chunks
rf
.
write
(
chunk
)
added
.
append
(
self
.
_info
(
path
))
return
{
'added'
:
added
}
def
upload
(
self
,
files
,
parent
):
""" For now, this uses a very naive way of storing files - the entire
file is read in to the File model's content field in one go.
...
...
coco/sftp.py
View file @
278a4200
...
...
@@ -390,7 +390,7 @@ class InternalSFTPClient(SFTPServer):
super
()
.
__init__
(
fake_server
)
def
listdir_attr
(
self
,
path
):
return
self
.
list_folder
(
path
)
return
self
.
list_folder
.
__wrapped__
(
self
,
path
)
def
open
(
self
,
path
,
mode
,
**
kwargs
):
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
...
...
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