source: prextra/@ftp/ftp.m @ 114

Last change on this file since 114 was 113, checked in by bduin, 8 years ago
File size: 2.1 KB
RevLine 
[113]1function 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
16error(javachk('jvm','The FTP object'))
17
18% Short-circuit cases.
19if (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
33elseif isa(host,'ftp')
34   % If given an FTP object, give it back.
35   h = host;
36   return
37end
38
39% Agrument parsing
40error(nargchk(1,3,nargin))
41switch nargin
42case 3
43    % Everything passed in.
44case 1
45    % Default to anonymous login
46    username = 'anonymous';
47    password = 'anonymous@example.com';
48otherwise
49    error('MATLAB:ftp:IncorrectArgumentCount','Incorrect number of arguments.')
50end
51
52% Immutable fields.
53h.jobject = org.apache.commons.net.ftp.FTPClient;
54colon = find(host==':');
55if isempty(colon)
56    h.host = host;
57    h.port = 21;
58else
59    h.host = host(1:colon-1);
60    h.port = str2double(host(colon+1:end));
61end
62h.username = username;
63h.password = password;
64
65% Mutable fields.  Use StringBuffers so these will act as references.
66h.remotePwd = java.lang.StringBuffer('');
67h.type = java.lang.StringBuffer('binary');
68
69% Keep track of passive/active mode
70% Added by Idin Motedayen-Aval
71h.passiveMode = java.lang.StringBuffer('p');
72
73% Make the cast.
74h = class(h,'ftp');
75
76% Connect.
77connect(h)
Note: See TracBrowser for help on using the repository browser.