sftphelper

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2017 License: GPL-3.0 Imports: 9 Imported by: 0

README

sftphelper

This package provides an easy to use wrapper for the golang sftp package

Exported Functions

ConnectWithKeyFile
Input:
	host string,
	username string,
	privkeyfile string
Returns:
	SFTPConnection
ConnectWithPassword
Input:
	host string,
	username string,
	password string
Returns:
	SFTPConnection
type SFTPConnection
type SFTPConnection struct {
	SftpClient *sftp.Client
IsVerbose  bool
}
func (*SFTPConnection) DownloadFiles(source string, target string) error
func (*SFTPConnection) UploadFile(sourcePath, targetPath string) error
func (*SFTPConnection) RemoveFile(sourcePath string) error
func (*SFTPConnection) WalkDirectories(path string, callback CallbackFunc) error
func (*SFTPConnection) WalkFiles(path string, callback CallbackFunc) error
func (*SFTPConnection) Close() error

Example Usage

import ("sftphelper")

Connect With Key File: sftpConnection, err := sftphelper.ConnectWithKeyFile("test.sftpserver.com", "ec2-user", "/home/me/.ssh/sftpkeyfile.pem")

OR

Connect With Password: sftpConnection, err := sftphelper.ConnectWithKeyFile("test.sftpserver.com", "ec2-user", "password1")

sftpConnection.DownloadFiles("/home/ftptest/sourcePath/", "/home/me/")

Contributors

Maria DeSouza maria.g.desouza@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyFilePath

func KeyFilePath(filename string) (path string)

KeyFilePath : Gets Key File Path - User Home directory + .ssh + key file name

func UserHomeDir

func UserHomeDir() (homedir string)

UserHomeDir : Gets Users Home Directory

Types

type CallbackFunc

type CallbackFunc func(sftpConnection *SFTPConnection, filePath string, fileName string)

CallbackFunc : Callback function template

type SFTPConnection

type SFTPConnection struct {
	SftpClient *sftp.Client
	IsVerbose  bool
}

SFTPConnection : Main connection

func ConnectWithKeyFile

func ConnectWithKeyFile(host, username, privkeyfile string) (*SFTPConnection, error)

ConnectWithKeyFile : This function will get an sftp conenction using the private key file Returns client ssh connection handler and error object if fails Host - ftp server name with or without port Username - ftp user (e.g ec2-user) privkeyfile - Fully qualified Private key file name

func ConnectWithPassword

func ConnectWithPassword(host, username, password string) (*SFTPConnection, error)

ConnectWithPassword : This function will get an sftp conenction using a password Returns client ssh connection handler and error object if fails Host - sftp server name with or without port Username - sftp user (e.g ec2-user) password - password for sftp user

func (*SFTPConnection) Close

func (sftpConnection *SFTPConnection) Close() error

Close : Close the SFTP Session

func (*SFTPConnection) DownloadFiles

func (sftpConnection *SFTPConnection) DownloadFiles(source string, target string) error

DownloadFiles : This function will download all files from ftp_server folder to the folder including sub-folders Return: error if fails source - remote Source directory target - local TargetDir

func (*SFTPConnection) RemoveFile

func (sftpConnection *SFTPConnection) RemoveFile(sourcePath string) error

RemoveFile : Removes a file from FTP Server

func (*SFTPConnection) UploadFile

func (sftpConnection *SFTPConnection) UploadFile(sourcePath, targetPath string) error

UploadFile : Copy source file to target

func (*SFTPConnection) WalkDirectories

func (sftpConnection *SFTPConnection) WalkDirectories(path string, callback CallbackFunc) error

WalkDirectories : Iterates over all the inner directories and calls a processing function

func (*SFTPConnection) WalkFiles

func (sftpConnection *SFTPConnection) WalkFiles(path string, callback CallbackFunc) error

WalkFiles : Iterates over all the inner files in the remote directory and calls a processing function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL