[113] | 1 | function h = ftp(host,username,password) |
---|
| 2 | % FTP Create an FTP object. |
---|
| 3 | % FTP(host,username,password) returns an FTP object. If only a host is |
---|
| 4 | % specified, it defaults to "anonymous" login. |
---|
| 5 | % |
---|
| 6 | % An alternate port can be specified by separating it from the host name |
---|
| 7 | % with a colon. For example: ftp('ftp.mathworks.com:34') |
---|
| 8 | |
---|
| 9 | % Matthew J. Simoneau, 14-Nov-2001 |
---|
| 10 | % Copyright 1984-2008 The MathWorks, Inc. |
---|
| 11 | % $Revision: 1.1.4.3 $ $Date: 2008/11/04 21:20:59 $ |
---|
| 12 | |
---|
| 13 | % Our FTP implementation uses code from the Apache Jakarta Project. |
---|
| 14 | % Copyright (c) 2001 The Apache Software Foundation. All rights reserved. |
---|
| 15 | |
---|
| 16 | error(javachk('jvm','The FTP object')) |
---|
| 17 | |
---|
| 18 | % Short-circuit cases. |
---|
| 19 | if (nargin == 0) |
---|
| 20 | % All MATLAB objects need a default constructor. It is useless, though. |
---|
| 21 | % Immutable fields. |
---|
| 22 | h.jobject = org.apache.commons.net.ftp.FTPClient; |
---|
| 23 | h.host = ''; |
---|
| 24 | h.port = 21; |
---|
| 25 | h.username = ''; |
---|
| 26 | h.password = ''; |
---|
| 27 | % Mutable fields. Use StringBuffers so these will act as references. |
---|
| 28 | h.remotePwd = java.lang.StringBuffer(''); |
---|
| 29 | h.type = java.lang.StringBuffer('binary'); |
---|
| 30 | % Make the cast. |
---|
| 31 | h = class(h,'ftp'); |
---|
| 32 | return |
---|
| 33 | elseif isa(host,'ftp') |
---|
| 34 | % If given an FTP object, give it back. |
---|
| 35 | h = host; |
---|
| 36 | return |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | % Agrument parsing |
---|
[128] | 40 | narginchk(1,3) |
---|
[113] | 41 | switch nargin |
---|
| 42 | case 3 |
---|
| 43 | % Everything passed in. |
---|
| 44 | case 1 |
---|
| 45 | % Default to anonymous login |
---|
| 46 | username = 'anonymous'; |
---|
| 47 | password = 'anonymous@example.com'; |
---|
| 48 | otherwise |
---|
| 49 | error('MATLAB:ftp:IncorrectArgumentCount','Incorrect number of arguments.') |
---|
| 50 | end |
---|
| 51 | |
---|
| 52 | % Immutable fields. |
---|
| 53 | h.jobject = org.apache.commons.net.ftp.FTPClient; |
---|
| 54 | colon = find(host==':'); |
---|
| 55 | if isempty(colon) |
---|
| 56 | h.host = host; |
---|
| 57 | h.port = 21; |
---|
| 58 | else |
---|
| 59 | h.host = host(1:colon-1); |
---|
| 60 | h.port = str2double(host(colon+1:end)); |
---|
| 61 | end |
---|
| 62 | h.username = username; |
---|
| 63 | h.password = password; |
---|
| 64 | |
---|
| 65 | % Mutable fields. Use StringBuffers so these will act as references. |
---|
| 66 | h.remotePwd = java.lang.StringBuffer(''); |
---|
| 67 | h.type = java.lang.StringBuffer('binary'); |
---|
| 68 | |
---|
| 69 | % Keep track of passive/active mode |
---|
| 70 | % Added by Idin Motedayen-Aval |
---|
| 71 | h.passiveMode = java.lang.StringBuffer('p'); |
---|
| 72 | |
---|
| 73 | % Make the cast. |
---|
| 74 | h = class(h,'ftp'); |
---|
| 75 | |
---|
| 76 | % Connect. |
---|
| 77 | connect(h) |
---|