[1582] | 1 | function scpout(host,path,packages)
|
---|
| 2 | %SCPOUT send packages to a host, using scp on unix, and pscp on windows
|
---|
| 3 | %
|
---|
| 4 | % usage: scpout(host,path,packages)
|
---|
| 5 | %
|
---|
| 6 | %
|
---|
| 7 |
|
---|
| 8 | %get hostname
|
---|
| 9 | hostname=oshostname();
|
---|
| 10 |
|
---|
| 11 | %if hostname and host are the same, do a simple copy
|
---|
| 12 |
|
---|
| 13 | if strcmpi(host,hostname),
|
---|
| 14 | for i=1:numel(packages),
|
---|
| 15 | copyfile(packages{i},path);
|
---|
| 16 | end
|
---|
| 17 | else
|
---|
| 18 | if ispc,
|
---|
| 19 | %use the putty project pscp.exe: it should be in the path.
|
---|
| 20 |
|
---|
| 21 | %get ISSM_DIR variable
|
---|
| 22 | [status,ISSM_DIR]=system('echo [%ISSM_DIR_WIN%]');
|
---|
| 23 | if status,
|
---|
| 24 | error('scpout error message: could not find ISSM_DIR_WIN envirnoment variable');
|
---|
| 25 | end
|
---|
| 26 | ISSM_DIR=ISSM_DIR(2:end-2);
|
---|
| 27 |
|
---|
| 28 | username=input('Username: (quoted string) ');
|
---|
| 29 | password=input('Password: (quoted string) ');
|
---|
| 30 |
|
---|
| 31 | for i=1:numel(packages),
|
---|
| 32 | [status,result]=system([ISSM_DIR '/externalpackages/ssh/pscp.exe -l "' username '" -pw "' password '" ' packages{i} ' ' host ':' path]);
|
---|
| 33 | if status,
|
---|
| 34 | error('scpout error message: could not call putty pscp');
|
---|
| 35 | end
|
---|
| 36 | end
|
---|
| 37 | error;
|
---|
| 38 |
|
---|
| 39 | else
|
---|
| 40 | %just use standard unix scp
|
---|
| 41 | %create string of packages being sent
|
---|
| 42 | string='';
|
---|
| 43 | for i=1:numel(packages),
|
---|
| 44 | string=[string ' ' packages{i}];
|
---|
| 45 | end
|
---|
| 46 | string=[string ' '];
|
---|
| 47 | [status,result]=system(['scp ' string host ':' path]);
|
---|
| 48 | if status,
|
---|
| 49 | error('scpout error message: could not call scp on *nix system');
|
---|
| 50 | end
|
---|
| 51 | end
|
---|
| 52 | end
|
---|