Documentation
¶
Overview ¶
Package ftp implements a FTP client as described in RFC 959.
Index ¶
- Constants
- func ISO8859_15ToUTF8(s string) string
- func ParseMListTime(sTime string) (t time.Time, err error)
- func UTF8ToISO8859_15(c string) string
- type Entry
- type EntryEx
- type EntryType
- type ServerConn
- func (c *ServerConn) ChangeDir(path string) error
- func (c *ServerConn) ChangeDirToParent() error
- func (c *ServerConn) CurrentDir() (string, error)
- func (c *ServerConn) Delete(path string) error
- func (c *ServerConn) Join(elem ...string) string
- func (c *ServerConn) List(path string) (entries []*Entry, err error)
- func (c *ServerConn) Login(user, password string) error
- func (c *ServerConn) Logout() error
- func (c *ServerConn) Lstat(name string) (entry os.FileInfo, err error)
- func (c *ServerConn) MInfo(path string) (entry EntryEx, err error)
- func (c *ServerConn) MList(path string) (entries []EntryEx, err error)
- func (c *ServerConn) MakeDir(path string) error
- func (c *ServerConn) NameList(path string) (entries []string, err error)
- func (c *ServerConn) NoOp() error
- func (c *ServerConn) Quit() error
- func (c *ServerConn) ReadDir(dirname string) (entries []os.FileInfo, err error)
- func (c *ServerConn) RemoveDir(path string) error
- func (c *ServerConn) Rename(from, to string) error
- func (c *ServerConn) Retr(path string) (io.ReadCloser, error)
- func (c *ServerConn) RetrFrom(path string, offset uint64) (io.ReadCloser, error)
- func (c *ServerConn) Stor(path string, r io.Reader) error
- func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error
Constants ¶
const ( // Time Layout used by MLSD/MLST (without fractions of second) TimeLayoutMlsx = "20060102150405" // Time Layout used by MLSD/MLST (including fractions of second) TimeLayoutMlsxFrac = "20060102150405.9" )
const ( // Positive Preliminary reply StatusInitiating = 100 StatusRestartMarker = 110 StatusReadyMinute = 120 StatusAlreadyOpen = 125 StatusAboutToSend = 150 // Positive Completion reply StatusCommandOK = 200 StatusCommandNotImplemented = 202 StatusSystem = 211 StatusDirectory = 212 StatusFile = 213 StatusHelp = 214 StatusName = 215 StatusReady = 220 StatusClosing = 221 StatusDataConnectionOpen = 225 StatusClosingDataConnection = 226 StatusPassiveMode = 227 StatusLongPassiveMode = 228 StatusExtendedPassiveMode = 229 StatusLoggedIn = 230 StatusLoggedOut = 231 StatusLogoutAck = 232 StatusRequestedFileActionOK = 250 StatusPathCreated = 257 // Positive Intermediate reply StatusUserOK = 331 StatusLoginNeedAccount = 332 StatusRequestFilePending = 350 // Transient Negative Completion reply StatusNotAvailable = 421 StatusCanNotOpenDataConnection = 425 StatusTransfertAborted = 426 StatusInvalidCredentials = 430 StatusFileActionIgnored = 450 StatusActionAborted = 451 Status452 = 452 // Permanent Negative Completion reply StatusBadCommand = 500 StatusBadArguments = 501 StatusNotImplemented = 502 StatusBadSequence = 503 StatusNotImplementedParameter = 504 StatusNotLoggedIn = 530 StatusStorNeedAccount = 532 StatusPageTypeUnknown = 551 StatusExceededStorage = 552 StatusBadFileName = 553 )
Variables ¶
This section is empty.
Functions ¶
func ISO8859_15ToUTF8 ¶
ISO8859_15ToUTF8 converts an ISO-8859-15 string to UTF-8 encoding
func ParseMListTime ¶
ParseMListTime parses a time fact returned by MLS(D|T). Format is YYYYMMDDHHMMSS[.F...]
func UTF8ToISO8859_15 ¶
UTF8ToISO8859_15 converts a UTF-8 string to ISO-8859-15 encoding
Types ¶
type EntryEx ¶
type EntryEx struct { // facts describing the file. Keys for standard facts (lowercase): size, modify, create, type (), unique, perm, lang, media-type, charset Facts map[string]string // contains filtered or unexported fields }
EntryEx describes a file and is returned by MList() and MInfo(). EntryEx implements the FileInfo interface
type ServerConn ¶
type ServerConn struct { // translate filename encoding from/to ISO 8859-15 if server does not support UTF-8 TranslateEncoding bool // list "." and ".." ListDotDirs bool // contains filtered or unexported fields }
ServerConn represents the connection to a remote FTP server.
func Connect ¶
func Connect(addr string) (*ServerConn, error)
Connect initializes the connection to the specified ftp server address.
It is generally followed by a call to Login() as most FTP commands require an authenticated user.
func (*ServerConn) ChangeDir ¶
func (c *ServerConn) ChangeDir(path string) error
ChangeDir issues a CWD FTP command, which changes the current directory to the specified path.
func (*ServerConn) ChangeDirToParent ¶
func (c *ServerConn) ChangeDirToParent() error
ChangeDirToParent issues a CDUP FTP command, which changes the current directory to the parent directory. This is similar to a call to ChangeDir with a path set to "..".
func (*ServerConn) CurrentDir ¶
func (c *ServerConn) CurrentDir() (string, error)
CurrentDir issues a PWD FTP command, which Returns the path of the current directory.
func (*ServerConn) Delete ¶
func (c *ServerConn) Delete(path string) error
Delete issues a DELE FTP command to delete the specified file from the remote FTP server.
func (*ServerConn) Join ¶
func (c *ServerConn) Join(elem ...string) string
Join joins any number of path elements into a single path, adding a separator if necessary. The result is Cleaned; in particular, all empty strings are ignored.
The separator is FileSystem specific.
func (*ServerConn) List ¶
func (c *ServerConn) List(path string) (entries []*Entry, err error)
List issues a LIST FTP command.
func (*ServerConn) Login ¶
func (c *ServerConn) Login(user, password string) error
Login authenticates the client with specified user and password.
"anonymous"/"anonymous" is a common user/password scheme for FTP servers that allows anonymous read-only accounts.
func (*ServerConn) Logout ¶
func (c *ServerConn) Logout() error
Logout issues a REIN FTP command to logout the current user.
func (*ServerConn) Lstat ¶
func (c *ServerConn) Lstat(name string) (entry os.FileInfo, err error)
Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.
func (*ServerConn) MInfo ¶
func (c *ServerConn) MInfo(path string) (entry EntryEx, err error)
MInfo issues an MLST command, which returns info about the specified directory entry in a standard format
func (*ServerConn) MList ¶
func (c *ServerConn) MList(path string) (entries []EntryEx, err error)
MList issues an MLSD command, which lists a directory in a standard format
func (*ServerConn) MakeDir ¶
func (c *ServerConn) MakeDir(path string) error
MakeDir issues a MKD FTP command to create the specified directory on the remote FTP server.
func (*ServerConn) NameList ¶
func (c *ServerConn) NameList(path string) (entries []string, err error)
NameList issues an NLST FTP command.
func (*ServerConn) NoOp ¶
func (c *ServerConn) NoOp() error
NoOp issues a NOOP FTP command. NOOP has no effects and is usually used to prevent the remote FTP server to close the otherwise idle connection.
func (*ServerConn) Quit ¶
func (c *ServerConn) Quit() error
Quit issues a QUIT FTP command to properly close the connection from the remote FTP server.
func (*ServerConn) ReadDir ¶
func (c *ServerConn) ReadDir(dirname string) (entries []os.FileInfo, err error)
ReadDir reads the directory named by dirname and returns a list of directory entries.
func (*ServerConn) RemoveDir ¶
func (c *ServerConn) RemoveDir(path string) error
RemoveDir issues a RMD FTP command to remove the specified directory from the remote FTP server.
func (*ServerConn) Rename ¶
func (c *ServerConn) Rename(from, to string) error
Rename renames a file on the remote FTP server.
func (*ServerConn) Retr ¶
func (c *ServerConn) Retr(path string) (io.ReadCloser, error)
Retr issues a RETR FTP command to fetch the specified file from the remote FTP server.
The returned ReadCloser must be closed to cleanup the FTP data connection.
func (*ServerConn) RetrFrom ¶
func (c *ServerConn) RetrFrom(path string, offset uint64) (io.ReadCloser, error)
RetrFrom issues a RETR FTP command to fetch the specified file from the remote FTP server, the server will not send the offset first bytes of the file.
The returned ReadCloser must be closed to cleanup the FTP data connection.
func (*ServerConn) Stor ¶
func (c *ServerConn) Stor(path string, r io.Reader) error
Stor issues a STOR FTP command to store a file to the remote FTP server. Stor creates the specified file with the content of the io.Reader.
Hint: io.Pipe() can be used if an io.Writer is required.