1package Net::SSH2::SFTP;
2
3use strict;
4use warnings;
5use Carp;
6
7sub die_with_error {
8    my $self = shift;
9    if (my ($code, $name) = $self->error) {
10        croak join(": ", @_, "SFTP error $code $name");
11    }
12    else {
13        croak join(": ", @_, "no SFTP error registered");
14    }
15}
16
17
181;
19__END__
20
21=head1 NAME
22
23Net::SSH2::SFTP - SSH 2 Secure FTP object
24
25=head1 DESCRIPTION
26
27An SFTP object is created by the L<Net::SSH2> C<sftp> method.
28
29=head2 error
30
31Returns the last SFTP error (one of the LIBSSH2_FX_* constants).  Use this
32when Net::SSH2::error returns LIBSSH2_ERROR_SFTP_PROTOCOL.  In list context,
33returns (code, error name).
34
35=head2 die_with_error( [message] )
36
37Calls C<die> with the given message and the error information from the
38object appended.
39
40=head2 open ( file [, flags [, mode ]]] )
41
42Open or create a file on the remote host.  The flags are the standard O_RDONLY,
43O_WRONLY, O_RDWR, O_APPEND, O_CREAT, O_TRUNC, and O_EXCL, which may be
44combined as usual.  Flags default to O_RDONLY and mode to 0666 (create only).
45Returns a L<Net::SSH2::File> object on success.
46
47=head2 opendir ( dir )
48
49Open a directory on the remote host; returns a Net::SSH2::Dir object on success.
50
51=head2 unlink ( file )
52
53Delete the remote file.
54
55=head2 rename ( old, new [, flags ] )
56
57Rename old to new.  Flags are taken from LIBSSH2_SFTP_RENAME_*, and may be
58combined; the default is to use all (overwrite, atomic, native).
59
60=head2 mkdir ( path [, mode ] )
61
62Create directory; mode defaults to 0777.
63
64=head2 rmdir ( path )
65
66Remove directory.
67
68=head2 stat ( path [, follow ] )
69
70Get file attributes for the given path.  If follow is set (default), will
71follow symbolic links.  On success, returns a hash containing the following:
72
73=over 4
74
75=item mode
76
77=item size
78
79=item uid
80
81=item gid
82
83=item atime
84
85=item mtime
86
87=back
88
89=head2 setstat ( path, key, value... )
90
91Set file attributes for given path; keys are the same as those returned by stat;
92note that it's not necessary to pass them all.
93
94=head2 symlink ( path, target [, type ] )
95
96Create a symbolic link to a given target.
97
98=head2 readlink ( path )
99
100Return the target of the given link, undef on failure.
101
102=head2 realpath ( path )
103
104Resolve a filename's path; returns the resolved path, or undef on error.
105
106=head1 SEE ALSO
107
108L<Net::SSH2>.
109
110Check L<Net::SFTP::Foreign> for a high level, perlish and easy to use
111SFTP client module. It can work on top of Net::SSH2 via the
112L<Net::SFTP::Foreign::Backend::Net_SSH2> backend module.
113
114=head1 AUTHOR
115
116David B. Robins, E<lt>dbrobins@cpan.orgE<gt>
117
118=head1 COPYRIGHT AND LICENSE
119
120Copyright (C) 2005, 2006 by David B. Robins; all rights reserved.
121
122This library is free software; you can redistribute it and/or modify
123it under the same terms as Perl itself, either Perl version 5.8.0 or,
124at your option, any later version of Perl 5 you may have available.
125
126=cut
127