Documentation
¶
Overview ¶
Package ftp implements the FTP client protocol as specified in RFC 959.
Index ¶
- Constants
- type Connection
- func (c *Connection) Abort() error
- func (c *Connection) Append(source io.Reader, path string) error
- func (c *Connection) ChangeDirUp() error
- func (c *Connection) ChangeWorkingDirTo(path string) error
- func (c *Connection) Close()
- func (c *Connection) Delete(path string) error
- func (c *Connection) Download(path string, dest io.Writer) error
- func (c *Connection) Help() (string, error)
- func (c *Connection) HelpAbout(topic string) (string, error)
- func (c *Connection) ListFileNames() ([]string, error)
- func (c *Connection) ListFileNamesIn(path string) ([]string, error)
- func (c *Connection) ListFiles() (string, error)
- func (c *Connection) ListFilesIn(path string) (string, error)
- func (c *Connection) Login(user, password string) error
- func (c *Connection) MakeDirectory(path string) (string, error)
- func (c *Connection) NoOperation() error
- func (c *Connection) PrintWorkingDirectory() (string, error)
- func (c *Connection) Quit() error
- func (c *Connection) Reinitialize() error
- func (c *Connection) RemoveDirectory(path string) error
- func (c *Connection) RenameFromTo(from, to string) error
- func (c *Connection) Status() (StatusType, string, error)
- func (c *Connection) StatusOf(path string) (StatusType, string, error)
- func (c *Connection) StructureMount(path string) error
- func (c *Connection) System() (string, error)
- func (c *Connection) Upload(source io.Reader, path string) error
- func (c *Connection) UploadUnique(source io.Reader) error
- type Logger
- type StatusType
Constants ¶
const ( GeneralStatus StatusType = "status" FileStatus = "file status" DirectoryStatus = "directory status" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is the network connection to an FTP server. The Connect functions return a *Connection which you have to Close after usage.
func Connect ¶
func Connect(host string, port uint16) (*Connection, error)
Connect establishes a connection to the given host on the given port. The standard FTP port is 21.
func ConnectLogging ¶
func ConnectLogging(host string, port uint16, logger Logger) (*Connection, error)
ConnectLogging establishes a connection to the given host on the given port. All messages sent and reveived over the control connection are additionally passed to the given Logger. The standard FTP port is 21.
func ConnectLoggingOn ¶
func ConnectLoggingOn(conn net.Conn, logger Logger) (*Connection, error)
ConnectLoggingOn uses the given connection as an FTP control connection. This can be used for setting connection parameters like time-outs. It also sets the logger.
func ConnectOn ¶
func ConnectOn(conn net.Conn) (*Connection, error)
ConnectOn uses the given connection as an FTP control connection. This can be used for setting connection parameters like time-outs.
func (*Connection) Abort ¶
func (c *Connection) Abort() error
Abort aborts the currently running file transaction (if any). If no file transfer is being executed or if shutting down the data connection was successful, the returned error will be nil. The FTP command this sends is ABOR.
func (*Connection) Append ¶
func (c *Connection) Append(source io.Reader, path string) error
Append appends the contents of the given source to a file at the given path on the server. If the file was there before, it is overwritten. Otherwise a new file is created. It file is written as binary in passive mode. The FTP command this sends is APPE.
func (*Connection) ChangeDirUp ¶
func (c *Connection) ChangeDirUp() error
ChangeDirUp moves the current working directory up one folder (like a 'cd ..' in the console). The FTP command this sends is CDUP.
func (*Connection) ChangeWorkingDirTo ¶
func (c *Connection) ChangeWorkingDirTo(path string) error
ChangeWorkingDirTo sets the given path as the working directory. The path argument is sent as is so make sure to surround the string with quotes if needed. The FTP command this sends is CWD
func (*Connection) Close ¶
func (c *Connection) Close()
Close closes the underlying TCP connection to the FTP server. Call this function when done. Closing does not send a QUIT message to the server so make sure to do that before-hand.
func (*Connection) Delete ¶
func (c *Connection) Delete(path string) error
Delete erases the given path from the FTP server. The path argument is sent as is so make sure to surround the string with quotes if needed. The FTP command this sends is DELE.
func (*Connection) Download ¶
func (c *Connection) Download(path string, dest io.Writer) error
Download writes the contents of the file at the given path into the given writer. It reads the file as binary data from the FTP server in passive mode. The FTP command this sends is RETR.
func (*Connection) Help ¶
func (c *Connection) Help() (string, error)
Help returns a human readable help message from the FTP server. This message does not contain any control codes. The FTP command this sends is HELP.
func (*Connection) HelpAbout ¶
func (c *Connection) HelpAbout(topic string) (string, error)
HelpAbout returns a human readable help message about the given topic from the FTP server. This message does not contain any control codes. The FTP command this sends is HELP.
func (*Connection) ListFileNames ¶
func (c *Connection) ListFileNames() ([]string, error)
ListFileNames returns a list of file names in the current working directory. The FTP command this sends is NLST.
func (*Connection) ListFileNamesIn ¶
func (c *Connection) ListFileNamesIn(path string) ([]string, error)
ListFileNamesIn returns a list of file names in the given directory. The path is sent as is so make sure to surround the string with quotes if needed. The FTP command this sends is NLST.
func (*Connection) ListFiles ¶
func (c *Connection) ListFiles() (string, error)
ListFiles returns detailed information about the current working directory. The result does not contain any control codes. The format of the result depends on the implementation of the server so no automatic parsing happens here. The FTP command this sends is LIST.
func (*Connection) ListFilesIn ¶
func (c *Connection) ListFilesIn(path string) (string, error)
ListFilesIn returns detailed information about the given file or directory. The result does not contain any control codes. The format of the result depends on the implementation of the server so no automatic parsing happens here. The path is sent as is so make sure to surround the string with quotes if needed. The FTP command this sends is LIST.
func (*Connection) Login ¶
func (c *Connection) Login(user, password string) error
Login sends the given user and, if required, password to the FTP server. If no password is required (the FTP server will respond accordingly) no password will be sent. In this case just pass an empty string for the password. The FTP commands this sends are USER and (optionally) PASS.
func (*Connection) MakeDirectory ¶
func (c *Connection) MakeDirectory(path string) (string, error)
MakeDirectory creates a new directory under the given path. Since this path may be relative to the current working directory and possibly not suited for a call to ChangeWorkingDirTo, on success (err is nil) the function returns the path to the newly created directory. The path is sent as is so make sure to surround the string with quotes if needed. The FTP command this sends is MKD.
func (*Connection) NoOperation ¶
func (c *Connection) NoOperation() error
NoOperation sends a message to the FTP server and makes sure the repsonse is OK. This can be used as a kind of ping to see if the server is still responding. The FTP command this sends is NOOP.
func (*Connection) PrintWorkingDirectory ¶
func (c *Connection) PrintWorkingDirectory() (string, error)
PrintWorkingDirectory returns the current working directory. The FTP command this sends is PWD.
func (*Connection) Quit ¶
func (c *Connection) Quit() error
Quit closes the current FTP session. It does not however close the underlying TCP connection. For that you need to call Close once you are done. The FTP command this sends is QUIT.
func (*Connection) Reinitialize ¶
func (c *Connection) Reinitialize() error
Reinitialize closes the current session and starts over again. You may want to Login again after this command. The FTP command this sends is REIN.
func (*Connection) RemoveDirectory ¶
func (c *Connection) RemoveDirectory(path string) error
RemoveDirectory erases the directory under the given path. The path is sent as is so make sure to surround the string with quotes if needed. The FTP command this sends is RMD.
func (*Connection) RenameFromTo ¶
func (c *Connection) RenameFromTo(from, to string) error
RenameFromTo changes the name of a file (from) to the new name (to). The paths are sent as is so make sure to surround the strings with quotes if needed. The FTP commands this sends are RNFR and RNTO.
func (*Connection) Status ¶
func (c *Connection) Status() (StatusType, string, error)
Status returns general status information about the FTP server process. The resulting string does not contain any control codes. The FTP command this sends is STAT.
func (*Connection) StatusOf ¶
func (c *Connection) StatusOf(path string) (StatusType, string, error)
StatusOf returns status information about the given path. It behaves like ListFilesIn if called with the path. The resulting string does not contain any control codes. The FTP command this sends is STAT.
func (*Connection) StructureMount ¶
func (c *Connection) StructureMount(path string) error
StructureMount mounts the given path. The path argument is sent as is so make sure to surround the string with quotes if needed. The FTP command this sends is SMNT.
func (*Connection) System ¶
func (c *Connection) System() (string, error)
System describes the system on which the FTP server is running. This may include the operating system and other information. The FTP command this sends is SYST.
func (*Connection) Upload ¶
func (c *Connection) Upload(source io.Reader, path string) error
Upload writes the contents of the given source to a file at the given path on the server. If the file was there before, it is overwritten. Otherwise a new file is created. The file is written as binary in passive mode. The FTP command this sends is STOR.
func (*Connection) UploadUnique ¶
func (c *Connection) UploadUnique(source io.Reader) error
UploadUnique writes the contents of the given source to a file at the given path on the server. If the file was there before, it is overwritten. Otherwise a new file is created. It file is written as binary in passive mode. The FTP command this sends is STOU.
type Logger ¶
type Logger interface { // SentFTP is called after a message is sent to the FTP server on the control // connection. If an error occurred during the sent it is given to the Logger // as well. SentFTP(msg []byte, err error) // ReceivedFTP is called after a message is received from FTP server on the control // connection. If an error occurred while receiving it is given to the Logger as well. ReceivedFTP(response []byte, err error) }
Logger can be used to log the raw messages on the FTP control connection.
func NewConsoleLogger ¶
func NewConsoleLogger() Logger
NewConsoleLogger creates a new logger that writes all messages sent and received to the console using fmt.Print. It can be used with ConnectLogging which might be helpful during debugging. If this is used in a GUI, note that ALL messages on the control connection are logged, including the password for the PASS command. You might not want the clear-text password to appear in the GUI.
type StatusType ¶
type StatusType string
StatusType describes the result of a Status or StatusOf command.