Net::SSH2::SFTP(3)

πŸ’– Net::SSH2::SFTP β€” the SSH 2 Secure FTP object, bestie edition πŸ’–

okay so this is the Net::SSH2::SFTP page from the Perl manual, and we are gonna make it make sense. sit with me. 🫢


✨ NAME ✨

Net::SSH2::SFTP</purl> β€” the SSH 2 Secure FTP object. that's it, that's the name, she's iconic, she's serving. πŸ‘‘


🌸 DESCRIPTION 🌸

An SFTP object is not something you just... find in the wild. You make one β€” you get it by calling the sftp method on a Net::SSH2 object. that's the origin story. main character energy fr. ✨


πŸŽ€ error

returns the last SFTP error. and when we say "the last SFTP error" we mean one of the LIBSSH2_FX_* constants, okay? πŸ’…

reach for this one when Net::SSH2::error hands you back LIBSSH2_ERROR_SFTP_PROTOCOL β€” that's your cue, that's the signal, go get the real tea. 🍡

and in list context, she gives you (code, error name). two things. a lil duo. 🫢

πŸŽ€ die_with_error( [message] )

calls die, but make it ✨informative✨ β€” it takes your message and appends the error info from the object. so you die, but you die with context. πŸ’€

πŸŽ€ open ( file [, flags [, mode ]]] )

open or create a file on the remote host. remote!! not on your laptop!! 🌈

the flags are the standard squad:

  • O_RDONLY
  • O_WRONLY
  • O_RDWR
  • O_APPEND
  • O_CREAT
  • O_TRUNC
  • O_EXCL

and yeah you can combine them, as usual, like a little friendship bracelet. 🧚

defaults, bestie, write these down:

  • flags default to O_RDONLY
  • mode defaults to 0666 (create only)

returns a Net::SSH2::File object on success. slay. πŸ’…

πŸŽ€ opendir ( dir )

opens a directory on the remote host. returns a Net::SSH2::Dir object on success. we love a return value that is an object. 😌

delete the remote file. gone. deleted. no undo. πŸ’€

πŸŽ€ rename ( old, new [, flags ] )

renames old to new. πŸ’«

the flags come from LIBSSH2_SFTP_RENAME_*, and you can combine them. the default is to use all of them β€” overwrite, atomic, native. she does the most, on purpose, and honestly? respect. πŸ‘‘

πŸŽ€ mkdir ( path [, mode ] )

makes a directory. mode defaults to 0777. πŸ“βœ¨

πŸŽ€ rmdir ( path )

removes a directory. bye bye directory. 🫢

πŸŽ€ stat ( path [, follow ] )

gets file attributes for the given path. πŸ”

if follow is set β€” and it is set by default β€” she'll follow symbolic links. πŸ¦‹

on success, returns a hash with all of this in it:

  • mode
  • size
  • uid
  • gid
  • atime
  • mtime

six keys. a whole little hash. πŸ’–

πŸŽ€ setstat ( path, key, value... )

sets file attributes for the given path. the keys are the same ones stat gives you back β€” same list, same names. 🎯

note: it is not necessary to pass them all. you can pass just the ones you care about. no pressure. πŸ™ˆ

creates a symbolic link to a given target. πŸ”—

returns the target of the given link. and if it fails? undef. 😭 that's it, that's the failure mode.

πŸŽ€ realpath ( path )

resolves a filename's path. returns the resolved path, or undef on error. 🧭


🌈 SEE ALSO 🌈

  • Net::SSH2.
  • Check Net::SFTP::Foreign if you want a high level, perlish and easy to use SFTP client module. she's giving convenience. πŸ’… and guess what β€” it can work on top of Net::SSH2 via the Net::SFTP::Foreign::Backend::Net_SSH2 backend module. iykyk. 🫢

⭐ AUTHOR ⭐

David B. Robins, <dbrobins@cpan.org> β€” ty for your service king πŸ«‘πŸ’œ


Copyright (C) 2005, 2006 by David B. Robins; all rights reserved. yes, all of them. every single right. πŸ’…

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available. so like. go forth. remix. πŸŽ€βœ¨


and that's the whole page, bestie!! this was Net::SSH2::SFTP(3), part of perl v5.42.0, dated 2025-07-25 β€” mwah, no cap, fr fr, go open some remote files responsibly. πŸ’–πŸ¦‹πŸŒΈπŸŽ€πŸ’…πŸ«Ά

πŸ“¦ where this page comes from