Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ludovic Kiefer
erp5
Commits
dbaaff66
Commit
dbaaff66
authored
Aug 04, 2014
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Type.ConnectionPlugin.SFTPConnection: Add bind address support.
Requires creating socket outside of paramiko.Transport .
parent
4781d9c8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
product/ERP5Type/ConnectionPlugin/SFTPConnection.py
product/ERP5Type/ConnectionPlugin/SFTPConnection.py
+24
-3
No files found.
product/ERP5Type/ConnectionPlugin/SFTPConnection.py
View file @
dbaaff66
...
...
@@ -29,10 +29,11 @@
import
os
,
socket
from
urlparse
import
urlparse
from
socket
import
error
from
socket
import
error
,
socket
,
getaddrinfo
,
AF_UNSPEC
,
SOCK_STREAM
from
xmlrpclib
import
Binary
from
cStringIO
import
StringIO
from
paramiko
import
Transport
,
RSAKey
,
SFTPClient
from
paramiko.util
import
retry_on_signal
class
SFTPError
(
Exception
):
"""
...
...
@@ -45,20 +46,40 @@ class SFTPConnection:
Handle a SFTP (SSH over FTP) Connection
"""
def
__init__
(
self
,
url
,
user_name
,
password
=
None
,
private_key
=
None
):
def
__init__
(
self
,
url
,
user_name
,
password
=
None
,
private_key
=
None
,
bind_address
=
None
):
self
.
url
=
url
self
.
user_name
=
user_name
if
password
and
private_key
:
raise
SFTPError
(
"Password and private_key cannot be defined simultaneously"
)
self
.
password
=
password
self
.
private_key
=
private_key
self
.
bind_address
=
bind_address
def
connect
(
self
):
""" Get a handle to a remote connection """
# Check URL
schema
=
urlparse
(
self
.
url
)
if
schema
.
scheme
==
'sftp'
:
self
.
transport
=
Transport
((
schema
.
hostname
,
int
(
schema
.
port
)))
hostname
=
schema
.
hostname
port
=
int
(
schema
.
port
)
# Socket creation code inspired from paramiko.Transport.__init__
# with added bind support.
for
family
,
socktype
,
_
,
_
,
_
in
getaddrinfo
(
hostname
,
port
,
AF_UNSPEC
,
SOCK_STREAM
,
):
if
socktype
==
SOCK_STREAM
:
sock
=
socket
(
family
,
SOCK_STREAM
)
if
self
.
bind_address
:
# XXX: Expects bind address to be of same family as hostname.
# May not be easy if name resolution is involved.
# Try to reconciliate them ?
sock
.
bind
((
self
.
bind_addres
,
0
))
retry_on_signal
(
lambda
:
sock
.
connect
((
hostname
,
port
)))
break
else
:
raise
SFTPError
(
'No suitable socket family found'
)
self
.
transport
=
Transport
(
sock
)
else
:
raise
SFTPError
(
'Not a valid sftp url %s, type is %s'
%
(
self
.
url
,
schema
.
scheme
))
# Add authentication to transport
...
...
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