@@ -1550,6 +1550,10 @@ def _list_outputs(self):
15501550class SSHDataGrabberInputSpec (DataGrabberInputSpec ):
15511551 hostname = traits .Str (mandatory = True ,
15521552 desc = 'Server hostname.' )
1553+ username = traits .Str (mandatory = False ,
1554+ desc = 'Server username.' )
1555+ password = traits .Password (mandatory = False ,
1556+ desc = 'Server password.' )
15531557 download_files = traits .Bool (True , usedefault = True ,
15541558 desc = 'If false it will return the file names without downloading them' )
15551559 base_directory = traits .Str (mandatory = True ,
@@ -1576,8 +1580,10 @@ class SSHDataGrabber(DataGrabber):
15761580
15771581 >>> from nipype.interfaces.io import SSHDataGrabber
15781582 >>> 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'
15811587
15821588 Pick all files from the base directory
15831589
@@ -1586,15 +1592,17 @@ class SSHDataGrabber(DataGrabber):
15861592 Pick all files starting with "s" and a number from current directory
15871593
15881594 >>> dg.inputs.template_expression = 'regexp'
1589- >>> dg.inputs.template = 's [0-9].*'
1595+ >>> dg.inputs.template = 'pop [0-9].*'
15901596
15911597 Same thing but with dynamically created fields
15921598
15931599 >>> 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'
15981606 >>> dg.inputs.arg2 = 'foo'
15991607
16001608 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):
16371645 try :
16381646 paramiko
16391647 except NameError :
1640- raise ImportError (
1648+ warn (
16411649 "The library parmiko needs to be installed"
16421650 " for this module to run."
16431651 )
16441652 if not outfields :
16451653 outfields = ['outfiles' ]
16461654 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+
16471663 if (
16481664 self .inputs .template_expression == 'regexp' and
16491665 self .inputs .template [- 1 ] != '$'
@@ -1652,6 +1668,14 @@ def __init__(self, infields=None, outfields=None, **kwargs):
16521668
16531669
16541670 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+
16551679 if len (self .inputs .ssh_log_to_file ) > 0 :
16561680 paramiko .util .log_to_file (self .inputs .ssh_log_to_file )
16571681 # infields are mandatory, however I could not figure out how to set 'mandatory' flag dynamically
0 commit comments