Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[add]:add connectTLS. (ftp over tls) #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion connect.go
@@ -1,11 +1,32 @@
package goftp

import (
"crypto/tls"
"bufio"
"log"
"net"
)

// ConnectTLS (FTP over TLS).
func ConnectTLS(addr string, config *tls.Config, debug bool) (*FTP, error) {
var err error
var conn net.Conn

if conn, err = net.Dial("tcp", addr); err != nil {
return nil, err
}
conn = tls.Client(conn, config)

writer := bufio.NewWriter(conn)
reader := bufio.NewReader(conn)

// reader.ReadString('\n')
object := &FTP{conn: conn, addr: addr, reader: reader, writer: writer, tlsconfig: config, debug: debug}
object.receive()

return object, nil
}

// Connect to server at addr (format "host:port"). debug is OFF
func Connect(addr string) (*FTP, error) {
var err error
Expand All @@ -18,7 +39,7 @@ func Connect(addr string) (*FTP, error) {
writer := bufio.NewWriter(conn)
reader := bufio.NewReader(conn)

//reader.ReadString('\n')
// reader.ReadString('\n')
object := &FTP{conn: conn, addr: addr, reader: reader, writer: writer, debug: false}
object.receive()

Expand Down