1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: namespace MOC\Module\Network\Ftp\File;
39: use MOC\Api;
40: use MOC\Generic\Device\Module;
41: use MOC\Module\Network\Ftp\File;
42:
43: 44: 45:
46: class Write extends Property implements Module {
47: 48: 49: 50: 51: 52:
53: public static function InterfaceChangelog() {
54: return Api::Core()->Changelog()->Create( __CLASS__ );
55: }
56:
57: 58: 59: 60: 61: 62:
63: public static function InterfaceDepending() {
64: return Api::Core()->Depending();
65: }
66:
67: 68: 69: 70: 71: 72:
73: public static function InterfaceInstance() {
74: return new Write();
75: }
76:
77: 78: 79: 80: 81: 82: 83:
84: public function Copy( $Path ) {
85: if( ftp_mdtm( $this->Connection()->Handler(), $this->Location() ) > -1 ) {
86: $Source = File::InterfaceInstance();
87: $Source->Connection( $this->Connection() );
88: $Source->Handle( $this->Location() );
89: $Target = File::InterfaceInstance();
90: $Target->Connection( $this->Connection() );
91: $Target->Handle( $Path.'/'.basename($this->Location()) );
92: $Target->Content( $Source->Content() );
93: $Target->Save();
94: $this->Location( $Target->Location() );
95: $this->UpdateProperties();
96: return true;
97: } else {
98: return false;
99: }
100: }
101:
102: 103: 104: 105: 106:
107: public function Save() {
108: $LocalFile = Api::Core()->Cache()->Group( __METHOD__ )->Identifier( $this->Location() )->Timeout( 9999999999 )->Set( $this->Content );
109: ftp_put( $this->Connection()->Handler(), $this->Location(), $LocalFile->Location(), FTP_BINARY );
110: $LocalFile->Remove();
111: $this->UpdateProperties();
112: $this->Changed( false );
113: return true;
114: }
115:
116: 117: 118: 119: 120: 121: 122:
123: public function SaveAs( $Location ) {
124: $LocalFile = Api::Core()->Cache()->Group( __METHOD__ )->Identifier( $this->Location() )->Timeout( 9999999999 )->Set( $this->Content );
125: ftp_put( $this->Connection()->Handler(), $this->UpdateSyntax( $Location ), $LocalFile->Location(), FTP_BINARY );
126: $LocalFile->Remove();
127: $this->Location( $Location );
128: $this->UpdateProperties();
129: $this->Changed( false );
130: return true;
131: }
132:
133: 134: 135: 136: 137: 138: 139:
140: public function Move( $Location ) {
141: if( ftp_mdtm( $this->Connection()->Handler(), $this->Location() ) > -1 ) {
142: $Result = ftp_rename( $this->Connection()->Handler(), $this->Location(), $this->UpdateSyntax( $Location ) );
143: $this->UpdateProperties();
144: return $Result;
145: } else {
146: return false;
147: }
148: }
149:
150: 151: 152: 153: 154:
155: public function Remove() {
156: if( ftp_mdtm( $this->Connection()->Handler(), $this->Location() ) > -1 ) {
157: return ftp_delete( $this->Connection()->Handler(), $this->Location() );
158: } else {
159: return false;
160: }
161: }
162:
163: 164: 165: 166: 167:
168: public function Touch() {
169: if( ftp_mdtm( $this->Connection()->Handler(), $this->Location() ) > -1 ) {
170: $Result = ftp_rename( $this->Connection()->Handler(), $this->Location(), $this->Location() );
171: $this->UpdateProperties();
172: return $Result;
173: } else {
174: return false;
175: }
176: }
177: }
178: