@@ -1550,6 +1550,10 @@ def _list_outputs(self):
1550
1550
class SSHDataGrabberInputSpec (DataGrabberInputSpec ):
1551
1551
hostname = traits .Str (mandatory = True ,
1552
1552
desc = 'Server hostname.' )
1553
+ username = traits .Str (mandatory = False ,
1554
+ desc = 'Server username.' )
1555
+ password = traits .Password (mandatory = False ,
1556
+ desc = 'Server password.' )
1553
1557
download_files = traits .Bool (True , usedefault = True ,
1554
1558
desc = 'If false it will return the file names without downloading them' )
1555
1559
base_directory = traits .Str (mandatory = True ,
@@ -1576,8 +1580,10 @@ class SSHDataGrabber(DataGrabber):
1576
1580
1577
1581
>>> from nipype.interfaces.io import SSHDataGrabber
1578
1582
>>> dg = SSHDataGrabber()
1579
- >>> dg.inputs.hostname = 'myhost.com'
1580
- >>> dg.inputs.base_directory = '/main_folder/my_remote_dir'
1583
+ >>> dg.inputs.hostname = 'test.rebex.net'
1584
+ >>> dg.inputs.user = 'demo'
1585
+ >>> dg.inputs.password = 'password'
1586
+ >>> dg.inputs.base_directory = 'pub/example'
1581
1587
1582
1588
Pick all files from the base directory
1583
1589
@@ -1586,15 +1592,17 @@ class SSHDataGrabber(DataGrabber):
1586
1592
Pick all files starting with "s" and a number from current directory
1587
1593
1588
1594
>>> dg.inputs.template_expression = 'regexp'
1589
- >>> dg.inputs.template = 's [0-9].*'
1595
+ >>> dg.inputs.template = 'pop [0-9].*'
1590
1596
1591
1597
Same thing but with dynamically created fields
1592
1598
1593
1599
>>> dg = SSHDataGrabber(infields=['arg1','arg2'])
1594
- >>> dg.inputs.hostname = 'myhost.com'
1595
- >>> dg.inputs.base_directory = '~/my_remote_dir'
1596
- >>> dg.inputs.template = '%s/%s.nii'
1597
- >>> dg.inputs.arg1 = 'foo'
1600
+ >>> dg.inputs.hostname = 'test.rebex.net'
1601
+ >>> dg.inputs.user = 'demo'
1602
+ >>> dg.inputs.password = 'password'
1603
+ >>> dg.inputs.base_directory = 'pub'
1604
+ >>> dg.inputs.template = '%s/%s.txt'
1605
+ >>> dg.inputs.arg1 = 'example'
1598
1606
>>> dg.inputs.arg2 = 'foo'
1599
1607
1600
1608
however this latter form can be used with iterables and iterfield in a
@@ -1637,13 +1645,21 @@ def __init__(self, infields=None, outfields=None, **kwargs):
1637
1645
try :
1638
1646
paramiko
1639
1647
except NameError :
1640
- raise ImportError (
1648
+ warn (
1641
1649
"The library parmiko needs to be installed"
1642
1650
" for this module to run."
1643
1651
)
1644
1652
if not outfields :
1645
1653
outfields = ['outfiles' ]
1646
1654
super (SSHDataGrabber , self ).__init__ (** kwargs )
1655
+ if (
1656
+ None in (self .inputs .username or self .inputs .password )
1657
+ ):
1658
+ raise ValueError (
1659
+ "either both username and password "
1660
+ "are provided or none of them"
1661
+ )
1662
+
1647
1663
if (
1648
1664
self .inputs .template_expression == 'regexp' and
1649
1665
self .inputs .template [- 1 ] != '$'
@@ -1652,6 +1668,14 @@ def __init__(self, infields=None, outfields=None, **kwargs):
1652
1668
1653
1669
1654
1670
def _list_outputs (self ):
1671
+ try :
1672
+ paramiko
1673
+ except NameError :
1674
+ raise ImportError (
1675
+ "The library parmiko needs to be installed"
1676
+ " for this module to run."
1677
+ )
1678
+
1655
1679
if len (self .inputs .ssh_log_to_file ) > 0 :
1656
1680
paramiko .util .log_to_file (self .inputs .ssh_log_to_file )
1657
1681
# infields are mandatory, however I could not figure out how to set 'mandatory' flag dynamically
0 commit comments