-
Notifications
You must be signed in to change notification settings - Fork 33
/
libssh2_sftp.pas
676 lines (593 loc) · 27.5 KB
/
libssh2_sftp.pas
1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
{ libssh2_sftp.pas } //# version: 2024.0114.1600
{ **..
* Delphi/Pascal Wrapper around the library "libssh2"
* Base repository:
* https://bitbucket.org/ZeljkoMarjanovic/libssh2-delphi
* Contributors:
* https://bitbucket.org/jeroenp/libssh2-delphi
* https://bitbucket.org/VadimLV/libssh2_delphi
* https://github.com/pult/libssh2_delphi/
* }
unit libssh2_sftp;
//#
//# **zm ** translated to pascal
//#
//# libssh2_sftp.h # https://github.com/libssh2/libssh2/blob/master/include/libssh2_sftp.h
//#TODO: # 2026.1122: https://github.com/libssh2/libssh2/commit/631e7734c8d850cd0c8e7a27d4dc524915e20b09
(*
* Copyright (C) Sara Golemon <[email protected]>
* Copyright (C) Daniel Stenberg
* Copyright (C) Simon Josefsson <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the copyright holder nor the names
* of any other contributors may be used to endorse or
* promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* SPDX-License-Identifier: BSD-3-Clause
*)
(* Note: Version 6 was documented at the time of writing }
* However it was marked as "DO NOT IMPLEMENT" due to pending changes }
* }
* Let's start with Version 3 (The version found in OpenSSH) and go from there }
*)
{$i libssh2.inc}
interface
uses
{$IFDEF allow_hvdll}
HVDll, //# alternative for: external '%dll_name%' name '%function_name%' delayed;
{$ENDIF}
{$IFDEF MSWINDOWS}
{$if defined(WIN32) or defined(WIN64)}
Windows,
{$else}
Wintypes, WinProcs,
{$ifend}
{$ENDIF}
SysUtils, libssh2;
const
LIBSSH2_SFTP_VERSION = 3;
LIBSSH2_SFTP_PACKET_MAXLEN = 40000;
type
_LIBSSH2_SFTP = record end;
LIBSSH2_SFTP_HANDLE = record end;
_LIBSSH2_SFTP_HANDLE = LIBSSH2_SFTP_HANDLE;
PLIBSSH2_SFTP = ^_LIBSSH2_SFTP;
PLIBSSH2_SFTP_HANDLE = ^LIBSSH2_SFTP_HANDLE;
const
LIBSSH2_SFTP_OPENFILE = 0;
LIBSSH2_SFTP_OPENDIR_ = 1;
{+// Flags for rename_ex()*/ }
LIBSSH2_SFTP_RENAME_OVERWRITE = $00000001;
LIBSSH2_SFTP_RENAME_ATOMIC = $00000002;
LIBSSH2_SFTP_RENAME_NATIVE = $00000004;
{+// Flags for stat_ex()*/ }
LIBSSH2_SFTP_STAT_ = 0;
LIBSSH2_SFTP_LSTAT_ = 1;
LIBSSH2_SFTP_SETSTAT_ = 2;
{+// Flags for symlink_ex()*/ }
LIBSSH2_SFTP_SYMLINK_ = 0;
LIBSSH2_SFTP_READLINK_ = 1;
LIBSSH2_SFTP_REALPATH_ = 2;
{+// SFTP attribute flag bits*/ }
LIBSSH2_SFTP_ATTR_SIZE = $00000001;
LIBSSH2_SFTP_ATTR_UIDGID = $00000002;
LIBSSH2_SFTP_ATTR_PERMISSIONS = $00000004;
LIBSSH2_SFTP_ATTR_ACMODTIME = $00000008;
LIBSSH2_SFTP_ATTR_EXTENDED = $80000000;
{+// If flags & ATTR_* bit is set, then the value in this struct will be }
{-* meaningful Otherwise it should be ignored }
{= }
type
_LIBSSH2_SFTP_ATTRIBUTES = record
flags: Cardinal;
filesize: LIBSSH2_UINT64_T;
uid, gid: Cardinal;
permissions: Cardinal;
atime, mtime: Cardinal;
end;
LIBSSH2_SFTP_ATTRIBUTES = _LIBSSH2_SFTP_ATTRIBUTES;
PLIBSSH2_SFTP_ATTRIBUTES = ^_LIBSSH2_SFTP_ATTRIBUTES;
_LIBSSH2_SFTP_STATVFS = record
f_bsize, {/* file system block size */}
f_frsize, {/* fragment size */}
f_blocks, {/* size of fs in f_frsize units */}
f_bfree, {/* # free blocks */}
f_bavail, {/* # free blocks for non-root */}
f_files, {/* # inodes */}
f_ffree, {/* # free inodes */}
f_favail, {/* # free inodes for non-root */}
f_fsid, {/* file system ID */}
f_flag, {/* mount flags */}
f_namemax: libssh2_uint64_t; {/* maximum filename length */}
end;
TLIBSSH2_SFTP_STATVFS = _LIBSSH2_SFTP_STATVFS;
PLIBSSH2_SFTP_STATVFS = ^TLIBSSH2_SFTP_STATVFS;
const
{+// SFTP filetypes*/ }
LIBSSH2_SFTP_TYPE_REGULAR = 1;
LIBSSH2_SFTP_TYPE_DIRECTORY = 2;
LIBSSH2_SFTP_TYPE_SYMLINK = 3;
LIBSSH2_SFTP_TYPE_SPECIAL = 4;
LIBSSH2_SFTP_TYPE_UNKNOWN = 5;
LIBSSH2_SFTP_TYPE_SOCKET = 6;
LIBSSH2_SFTP_TYPE_CHAR_DEVICE = 7;
LIBSSH2_SFTP_TYPE_BLOCK_DEVICE = 8;
LIBSSH2_SFTP_TYPE_FIFO = 9;
{+// }
{-* Reproduce the POSIX file modes here for systems that are not POSIX }
{-* compliant. }
{-* }
{-* These is used in "permissions" of "struct _LIBSSH2_SFTP_ATTRIBUTES" }
{= }
{+// File type*/ }
LIBSSH2_SFTP_S_IFMT = 61440; {/* type of file mask*/}
LIBSSH2_SFTP_S_IFIFO = 4096; {/* named pipe (fifo)*/}
LIBSSH2_SFTP_S_IFCHR = 8192; {/* character special*/}
LIBSSH2_SFTP_S_IFDIR = 16384; {/* directory*/}
LIBSSH2_SFTP_S_IFBLK = 24576; {/* block special*/}
LIBSSH2_SFTP_S_IFREG = 32768; {/* regular*/}
LIBSSH2_SFTP_S_IFLNK = 40960; {/* symbolic link*/}
LIBSSH2_SFTP_S_IFSOCK = 49152; {/* socket*/}
{+// File mode*/ }
{+// Read, write, execute/search by owner*/ }
LIBSSH2_SFTP_S_IRWXU = 448; {/* RWX mask for owner*/}
LIBSSH2_SFTP_S_IRUSR = 256; {/* R for owner*/}
LIBSSH2_SFTP_S_IWUSR = 128; {/* W for owner*/}
LIBSSH2_SFTP_S_IXUSR = 64; {/* X for owner*/}
{+// Read, write, execute/search by group*/ }
LIBSSH2_SFTP_S_IRWXG = 56; {/* RWX mask for group*/}
LIBSSH2_SFTP_S_IRGRP = 32; {/* R for group*/}
LIBSSH2_SFTP_S_IWGRP = 16; {/* W for group*/}
LIBSSH2_SFTP_S_IXGRP = 8; {/* X for group*/}
{+// Read, write, execute/search by others*/ }
LIBSSH2_SFTP_S_IRWXO = 7; {/* RWX mask for other*/}
LIBSSH2_SFTP_S_IROTH = 4; {/* R for other*/}
LIBSSH2_SFTP_S_IWOTH = 2; {/* W for other*/}
LIBSSH2_SFTP_S_IXOTH = 1; {/* X for other*/}
// ** zm: setuid/gid i sticky bit nisu definisani u originalnom header-u
LIBSSH2_SFTP_S_ISUID = 2048; // set UID bit
LIBSSH2_SFTP_S_ISGID = 1024; // set-group-ID bit
LIBSSH2_SFTP_S_ISVTX = 512; // sticky bit
{+// SFTP File Transfer Flags -- (e.g. flags parameter to sftp_open()) }
{=* Danger will robinson... APPEND doesn't have any effect on OpenSSH servers }
LIBSSH2_FXF_READ = $00000001;
LIBSSH2_FXF_WRITE = $00000002;
LIBSSH2_FXF_APPEND = $00000004;
LIBSSH2_FXF_CREAT = $00000008;
LIBSSH2_FXF_TRUNC = $00000010;
LIBSSH2_FXF_EXCL = $00000020;
{+// SFTP Status Codes (returned by libssh2_sftp_last_error() )*/ }
LIBSSH2_FX_OK = 0;
LIBSSH2_FX_EOF = 1;
LIBSSH2_FX_NO_SUCH_FILE = 2;
LIBSSH2_FX_PERMISSION_DENIED = 3;
LIBSSH2_FX_FAILURE = 4;
LIBSSH2_FX_BAD_MESSAGE = 5;
LIBSSH2_FX_NO_CONNECTION = 6;
LIBSSH2_FX_CONNECTION_LOST = 7;
LIBSSH2_FX_OP_UNSUPPORTED = 8;
LIBSSH2_FX_INVALID_HANDLE = 9;
LIBSSH2_FX_NO_SUCH_PATH = 10;
LIBSSH2_FX_FILE_ALREADY_EXISTS = 11;
LIBSSH2_FX_WRITE_PROTECT = 12;
LIBSSH2_FX_NO_MEDIA = 13;
LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM = 14;
LIBSSH2_FX_QUOTA_EXCEEDED = 15;
// LIBSSH2_FX_UNKNOWN_PRINCIPLE = 16; {/* Initial mis-spelling*/}
LIBSSH2_FX_UNKNOWN_PRINCIPAL = 16;
// LIBSSH2_FX_LOCK_CONFlICT = 17; {/* Initial mis-spelling*/}
LIBSSH2_FX_LOCK_CONFLICT = 17;
LIBSSH2_FX_DIR_NOT_EMPTY = 18;
LIBSSH2_FX_NOT_A_DIRECTORY = 19;
LIBSSH2_FX_INVALID_FILENAME = 20;
LIBSSH2_FX_LINK_LOOP = 21;
{+// Returned by any function that would block during a read/write opperation*/ }
LIBSSH2SFTP_EAGAIN = LIBSSH2_ERROR_EAGAIN;
{+// SFTP API*/ }
{$if not declared(uHVDll)}
function libssh2_sftp_init(session: PLIBSSH2_SESSION): PLIBSSH2_SFTP; cdecl;
{$else}
var libssh2_sftp_init: function(session: PLIBSSH2_SESSION): PLIBSSH2_SFTP; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_shutdown(sftp: PLIBSSH2_SFTP): Integer; cdecl;
{$else}
var libssh2_sftp_shutdown: function(sftp: PLIBSSH2_SFTP): Integer; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_last_error(sftp: PLIBSSH2_SFTP): ULong; cdecl;
{$else}
var libssh2_sftp_last_error: function(sftp: PLIBSSH2_SFTP): ULong; cdecl;
{$ifend}
{+// File / Directory Ops*/ }
{$if not declared(uHVDll)}
function libssh2_sftp_open_ex(sftp: PLIBSSH2_SFTP;
const filename: PAnsiChar;
filename_len: UInt;
flags: ULong;
mode: LongInt;
open_type: Integer): PLIBSSH2_SFTP_HANDLE; cdecl;
{$else}
var libssh2_sftp_open_ex: function(sftp: PLIBSSH2_SFTP;
const filename: PAnsiChar;
filename_len: UInt;
flags: ULong;
mode: LongInt;
open_type: Integer): PLIBSSH2_SFTP_HANDLE; cdecl;
{$ifend}
function libssh2_sftp_open(sftp: PLIBSSH2_SFTP;
const filename: PAnsiChar;
flags: ULong;
mode: LongInt): PLIBSSH2_SFTP_HANDLE; {$ifdef allow_inline}inline;{$endif}
function libssh2_sftp_opendir(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar): PLIBSSH2_SFTP_HANDLE; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_read(handle: PLIBSSH2_SFTP_HANDLE;
buffer: PAnsiChar;
buffer_maxlen: SIZE_T): Integer; cdecl;
{$else}
var libssh2_sftp_read: function(handle: PLIBSSH2_SFTP_HANDLE;
buffer: PAnsiChar;
buffer_maxlen: SIZE_T): Integer; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_readdir_ex(handle: PLIBSSH2_SFTP_HANDLE;
buffer: PAnsiChar;
buffer_maxlen: SIZE_T;
longentry: PAnsiChar;
longentry_maxlen: SIZE_T;
attrs: PLIBSSH2_SFTP_ATTRIBUTES): Integer; cdecl;
{$else}
var libssh2_sftp_readdir_ex: function(handle: PLIBSSH2_SFTP_HANDLE;
buffer: PAnsiChar;
buffer_maxlen: SIZE_T;
longentry: PAnsiChar;
longentry_maxlen: SIZE_T;
attrs: PLIBSSH2_SFTP_ATTRIBUTES): Integer; cdecl;
{$ifend}
function libssh2_sftp_readdir(handle: PLIBSSH2_SFTP_HANDLE;
buffer: PAnsiChar;
buffer_maxlen: SIZE_T; attrs: PLIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_write(handle: PLIBSSH2_SFTP_HANDLE;
const buffer: PAnsiChar;
count: SIZE_T): Integer; cdecl;
{$else}
var libssh2_sftp_write: function(handle: PLIBSSH2_SFTP_HANDLE;
const buffer: PAnsiChar;
count: SIZE_T): Integer; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_close_handle(handle: PLIBSSH2_SFTP_HANDLE): Integer; cdecl;
{$else}
var libssh2_sftp_close_handle: function(handle: PLIBSSH2_SFTP_HANDLE): Integer; cdecl;
{$ifend}
function libssh2_sftp_close(handle: PLIBSSH2_SFTP_HANDLE): Integer; {$ifdef allow_inline}inline;{$endif}
function libssh2_sftp_closedir(handle: PLIBSSH2_SFTP_HANDLE): Integer; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
procedure libssh2_sftp_seek(handle: PLIBSSH2_SFTP_HANDLE;
offset: SIZE_T); cdecl;
{$else}
var libssh2_sftp_seek: procedure(handle: PLIBSSH2_SFTP_HANDLE;
offset: SIZE_T); cdecl;
{$ifend}
{$if not declared(uHVDll)}
procedure libssh2_sftp_seek64(handle: PLIBSSH2_SFTP_HANDLE;
offset: LIBSSH2_UINT64_T); cdecl;
{$else}
var libssh2_sftp_seek64: procedure(handle: PLIBSSH2_SFTP_HANDLE;
offset: LIBSSH2_UINT64_T); cdecl;
{$ifend}
procedure libssh2_sftp_rewind(handle: PLIBSSH2_SFTP_HANDLE); {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_tell(handle: PLIBSSH2_SFTP_HANDLE): UInt; cdecl;
{$else}
var libssh2_sftp_tell: function(handle: PLIBSSH2_SFTP_HANDLE): UInt; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_tell64(handle: PLIBSSH2_SFTP_HANDLE): UInt64; cdecl;
{$else}
var libssh2_sftp_tell64: function(handle: PLIBSSH2_SFTP_HANDLE): UInt64; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_fstat_ex(handle: PLIBSSH2_SFTP_HANDLE;
var attrs: LIBSSH2_SFTP_ATTRIBUTES;
setstat: Integer): Integer; cdecl;
{$else}
var libssh2_sftp_fstat_ex: function(handle: PLIBSSH2_SFTP_HANDLE;
var attrs: LIBSSH2_SFTP_ATTRIBUTES;
setstat: Integer): Integer; cdecl;
{$ifend}
function libssh2_sftp_fstat(handle: PLIBSSH2_SFTP_HANDLE;
var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
function libssh2_sftp_fsetstat(handle: PLIBSSH2_SFTP_HANDLE;
var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
{+// Miscellaneous Ops*/ }
{$if not declared(uHVDll)}
function libssh2_sftp_rename_ex(sftp: PLIBSSH2_SFTP;
const source_filename: PAnsiChar;
srouce_filename_len: UInt;
const dest_filename: PAnsiChar;
dest_filename_len: UInt;
flags: LongInt): Integer; cdecl;
{$else}
var libssh2_sftp_rename_ex: function(sftp: PLIBSSH2_SFTP;
const source_filename: PAnsiChar;
srouce_filename_len: UInt;
const dest_filename: PAnsiChar;
dest_filename_len: UInt;
flags: LongInt): Integer; cdecl;
{$ifend}
function libssh2_sftp_rename(sftp: PLIBSSH2_SFTP;
const source_filename: PAnsiChar;
const dest_filename: PAnsiChar): Integer; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_unlink_ex(sftp: PLIBSSH2_SFTP;
const filename: PAnsiChar;
filename_len: UInt): Integer; cdecl;
{$else}
var libssh2_sftp_unlink_ex: function(sftp: PLIBSSH2_SFTP;
const filename: PAnsiChar;
filename_len: UInt): Integer; cdecl;
{$ifend}
function libssh2_sftp_unlink(sftp: PLIBSSH2_SFTP;
const filename: PAnsiChar): Integer; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_fstatvfs(handle: PLIBSSH2_SFTP_HANDLE;
var st: TLIBSSH2_SFTP_STATVFS): Integer; cdecl;
{$else}
var libssh2_sftp_fstatvfs: function(handle: PLIBSSH2_SFTP_HANDLE;
var st: TLIBSSH2_SFTP_STATVFS): Integer; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_statvfs(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: size_t;
var st: TLIBSSH2_SFTP_STATVFS): Integer; cdecl;
{$else}
var libssh2_sftp_statvfs: function(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: size_t;
var st: TLIBSSH2_SFTP_STATVFS): Integer; cdecl;
{$ifend}
{$if not declared(uHVDll)}
function libssh2_sftp_mkdir_ex(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt;
mode: LongInt): Integer; cdecl;
{$else}
var libssh2_sftp_mkdir_ex: function(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt;
mode: LongInt): Integer; cdecl;
{$ifend}
function libssh2_sftp_mkdir(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
mode: LongInt): Integer; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_rmdir_ex(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt): Integer; cdecl;
{$else}
var libssh2_sftp_rmdir_ex: function(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt): Integer; cdecl;
{$ifend}
function libssh2_sftp_rmdir(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar): Integer; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_stat_ex(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt;
stat_type: Integer;
var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; cdecl;
{$else}
var libssh2_sftp_stat_ex: function(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt;
stat_type: Integer;
var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; cdecl;
{$ifend}
function libssh2_sftp_stat(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
function libssh2_sftp_lstat(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
function libssh2_sftp_setstat(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
{$if not declared(uHVDll)}
function libssh2_sftp_symlink_ex(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt;
target: PAnsiChar;
target_len: UInt;
link_type: Integer): Integer; cdecl;
{$else}
var libssh2_sftp_symlink_ex: function(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
path_len: UInt;
target: PAnsiChar;
target_len: UInt;
link_type: Integer): Integer; cdecl;
{$ifend}
function libssh2_sftp_symlink(sftp: PLIBSSH2_SFTP;
const orig: PAnsiChar;
linkpath: PAnsiChar): Integer; {$ifdef allow_inline}inline;{$endif}
function libssh2_sftp_readlink(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
target: PAnsiChar;
maxlen: UInt): Integer; {$ifdef allow_inline}inline;{$endif}
function libssh2_sftp_realpath(sftp: PLIBSSH2_SFTP;
const path: PAnsiChar;
target: PAnsiChar;
maxlen: UInt): Integer; {$ifdef allow_inline}inline;{$endif}
implementation
{$if not declared(uHVDll)}
{$ifdef allow_delayed}
{$WARN SYMBOL_PLATFORM OFF} // W002
{$endif}
function libssh2_sftp_init; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_shutdown; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_last_error; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_open_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_read; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_readdir_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_write; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_close_handle; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
procedure libssh2_sftp_seek; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
procedure libssh2_sftp_seek64; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_tell; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_tell64; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_fstat_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_rename_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_unlink_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_fstatvfs; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_statvfs; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_mkdir_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_rmdir_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_stat_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
function libssh2_sftp_symlink_ex; external libssh2_name{$ifdef allow_delayed} delayed{$endif};
{$else}
var
dll_libssh2_sftp : TDll;
dll_libssh2_sftp_entires : array[0..20] of HVDll.TEntry = (
(Proc: @@libssh2_sftp_init; Name: 'libssh2_sftp_init'),
(Proc: @@libssh2_sftp_shutdown; Name: 'libssh2_sftp_shutdown'),
(Proc: @@libssh2_sftp_last_error; Name: 'libssh2_sftp_last_error'),
(Proc: @@libssh2_sftp_open_ex; Name: 'libssh2_sftp_open_ex'),
(Proc: @@libssh2_sftp_read; Name: 'libssh2_sftp_read'),
(Proc: @@libssh2_sftp_readdir_ex; Name: 'libssh2_sftp_readdir_ex'),
(Proc: @@libssh2_sftp_write; Name: 'libssh2_sftp_write'),
(Proc: @@libssh2_sftp_close_handle; Name: 'libssh2_sftp_close_handle'),
(Proc: @@libssh2_sftp_seek; Name: 'libssh2_sftp_seek'),
(Proc: @@libssh2_sftp_seek64; Name: 'libssh2_sftp_seek64'),
(Proc: @@libssh2_sftp_tell; Name: 'libssh2_sftp_tell'),
(Proc: @@libssh2_sftp_tell64; Name: 'libssh2_sftp_tell64'),
(Proc: @@libssh2_sftp_fstat_ex; Name: 'libssh2_sftp_fstat_ex'),
(Proc: @@libssh2_sftp_rename_ex; Name: 'libssh2_sftp_rename_ex'),
(Proc: @@libssh2_sftp_unlink_ex; Name: 'libssh2_sftp_unlink_ex'),
(Proc: @@libssh2_sftp_fstatvfs; Name: 'libssh2_sftp_fstatvfs'),
(Proc: @@libssh2_sftp_statvfs; Name: 'libssh2_sftp_statvfs'),
(Proc: @@libssh2_sftp_mkdir_ex; Name: 'libssh2_sftp_mkdir_ex'),
(Proc: @@libssh2_sftp_rmdir_ex; Name: 'libssh2_sftp_rmdir_ex'),
(Proc: @@libssh2_sftp_stat_ex; Name: 'libssh2_sftp_stat_ex'),
(Proc: @@libssh2_sftp_symlink_ex; Name: 'libssh2_sftp_symlink_ex')
);
{$ifend}
function libssh2_sftp_open(sftp: PLIBSSH2_SFTP; const filename: PAnsiChar; flags: ULong; mode: LongInt): PLIBSSH2_SFTP_HANDLE;
begin
Result := libssh2_sftp_open_ex(sftp, filename, Length(filename), flags, mode, LIBSSH2_SFTP_OPENFILE);
end;
function libssh2_sftp_opendir(sftp: PLIBSSH2_SFTP; const path: PAnsiChar): PLIBSSH2_SFTP_HANDLE;
begin
Result := libssh2_sftp_open_ex(sftp, path, Length(path), 0, 0, LIBSSH2_SFTP_OPENDIR_);
end;
function libssh2_sftp_readdir(handle: PLIBSSH2_SFTP_HANDLE; buffer: PAnsiChar; buffer_maxlen: SIZE_T; attrs: PLIBSSH2_SFTP_ATTRIBUTES): Integer;
begin
Result := libssh2_sftp_readdir_ex(handle, buffer, buffer_maxlen, nil, 0, attrs);
end;
function libssh2_sftp_close(handle: PLIBSSH2_SFTP_HANDLE): Integer;
begin
Result := libssh2_sftp_close_handle(handle);
end;
function libssh2_sftp_closedir(handle: PLIBSSH2_SFTP_HANDLE): Integer;
begin
Result := libssh2_sftp_close_handle(handle);
end;
procedure libssh2_sftp_rewind(handle: PLIBSSH2_SFTP_HANDLE);
begin
libssh2_sftp_seek64(handle, 0);
end;
function libssh2_sftp_fstat(handle: PLIBSSH2_SFTP_HANDLE; var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
begin
Result := libssh2_sftp_fstat_ex(handle, attrs, 0);
end;
function libssh2_sftp_fsetstat(handle: PLIBSSH2_SFTP_HANDLE; var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer; {$ifdef allow_inline}inline;{$endif}
begin
Result := libssh2_sftp_fstat_ex(handle, attrs, 1);
end;
function libssh2_sftp_rename(sftp: PLIBSSH2_SFTP; const source_filename: PAnsiChar; const dest_filename: PAnsiChar): Integer;
begin
Result := libssh2_sftp_rename_ex(sftp,
source_filename, Length(source_filename),
dest_filename, Length(dest_filename),
LIBSSH2_SFTP_RENAME_OVERWRITE or LIBSSH2_SFTP_RENAME_ATOMIC or LIBSSH2_SFTP_RENAME_NATIVE);
end;
function libssh2_sftp_unlink(sftp: PLIBSSH2_SFTP; const filename: PAnsiChar): Integer;
begin
Result := libssh2_sftp_unlink_ex(sftp, filename, Length(filename));
end;
function libssh2_sftp_mkdir(sftp: PLIBSSH2_SFTP; const path: PAnsiChar; mode: LongInt): Integer;
begin
Result := libssh2_sftp_mkdir_ex(sftp, path, Length(path), mode);
end;
function libssh2_sftp_rmdir(sftp: PLIBSSH2_SFTP; const path: PAnsiChar): Integer;
begin
Result := libssh2_sftp_rmdir_ex(sftp, path, Length(path));
end;
function libssh2_sftp_stat(sftp: PLIBSSH2_SFTP; const path: PAnsiChar; var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer;
begin
Result := libssh2_sftp_stat_ex(sftp, path, Length(path), LIBSSH2_SFTP_STAT_, attrs);
end;
function libssh2_sftp_lstat(sftp: PLIBSSH2_SFTP; const path: PAnsiChar; var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer;
begin
Result := libssh2_sftp_stat_ex(sftp, path, Length(path), LIBSSH2_SFTP_LSTAT_, attrs);
end;
function libssh2_sftp_setstat(sftp: PLIBSSH2_SFTP; const path: PAnsiChar; var attrs: LIBSSH2_SFTP_ATTRIBUTES): Integer;
begin
Result := libssh2_sftp_stat_ex(sftp, path, Length(path), LIBSSH2_SFTP_SETSTAT_, attrs);
end;
function libssh2_sftp_symlink(sftp: PLIBSSH2_SFTP; const orig: PAnsiChar; linkpath: PAnsiChar): Integer;
begin
Result := libssh2_sftp_symlink_ex(sftp, orig, Length(orig), linkpath, Length(linkpath), LIBSSH2_SFTP_SYMLINK_);
end;
function libssh2_sftp_readlink(sftp: PLIBSSH2_SFTP; const path: PAnsiChar; target: PAnsiChar; maxlen: UInt): Integer;
begin
Result := libssh2_sftp_symlink_ex(sftp, path, Length(path), target, maxlen, LIBSSH2_SFTP_READLINK_);
end;
function libssh2_sftp_realpath(sftp: PLIBSSH2_SFTP; const path: PAnsiChar; target: PAnsiChar; maxlen: UInt): Integer;
begin
Result := libssh2_sftp_symlink_ex(sftp, path, Length(path), target, maxlen, LIBSSH2_SFTP_REALPATH_);
end;
initialization
{$if declared(uHVDll)}
dll_libssh2_sftp := TDll.Create(libssh2_name, dll_libssh2_sftp_entires);
//dll_libssh2_sftp.Load(); // @dbg
{$ifend}
finalization
{$if declared(uHVDll)}
dll_libssh2_sftp.Unload;
{$ifend}
end.