aboutsummaryrefslogtreecommitdiff
path: root/sftp/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'sftp/server.go')
-rw-r--r--sftp/server.go34
1 files changed, 15 insertions, 19 deletions
diff --git a/sftp/server.go b/sftp/server.go
index 51db31a..be9f70a 100644
--- a/sftp/server.go
+++ b/sftp/server.go
@@ -4,12 +4,12 @@ package sftp
import (
"context"
- "log"
"encoding"
"errors"
"fmt"
"io"
"io/ioutil"
+ "log"
"os"
"strconv"
"sync"
@@ -21,7 +21,7 @@ import (
const (
// SftpServerWorkerCount defines the number of workers for the SFTP server
- SftpServerWorkerCount = 8
+ SftpServerWorkerCount = 1
)
// Server is an SSH File Transfer Protocol (sftp) server.
@@ -194,7 +194,7 @@ func handlePacket(s *Server, p orderedRequest) error {
case *sshFxpLstatPacket:
log.Println("pkt: lstat: ", p.Path)
// stat the requested file
- info, err := os.Lstat(toLocalPath(p.Path))
+ info, err := s.fs.Stat(s.ctx, p.Path)
rpkt = &sshFxpStatResponse{
ID: p.ID,
info: info,
@@ -219,43 +219,39 @@ func handlePacket(s *Server, p orderedRequest) error {
}
case *sshFxpMkdirPacket:
log.Println("pkt: mkdir: ", p.Path)
- err := os.Mkdir(toLocalPath(p.Path), 0755)
+ err := s.fs.Mkdir(s.ctx, p.Path, 0755)
rpkt = statusFromError(p.ID, err)
case *sshFxpRmdirPacket:
log.Println("pkt: rmdir: ", p.Path)
- err := os.Remove(toLocalPath(p.Path))
+ err := s.fs.RemoveAll(s.ctx, p.Path)
rpkt = statusFromError(p.ID, err)
case *sshFxpRemovePacket:
log.Println("pkt: rm: ", p.Filename)
- err := os.Remove(toLocalPath(p.Filename))
+ err := s.fs.RemoveAll(s.ctx, p.Filename)
rpkt = statusFromError(p.ID, err)
case *sshFxpRenamePacket:
log.Println("pkt: rename: ", p.Oldpath, ", ", p.Newpath)
- err := os.Rename(toLocalPath(p.Oldpath), toLocalPath(p.Newpath))
+ err := s.fs.Rename(s.ctx, p.Oldpath, p.Newpath)
rpkt = statusFromError(p.ID, err)
case *sshFxpSymlinkPacket:
log.Println("pkt: ln -s: ", p.Targetpath, ", ", p.Linkpath)
- err := os.Symlink(toLocalPath(p.Targetpath), toLocalPath(p.Linkpath))
+ err := s.fs.Rename(s.ctx, p.Targetpath, p.Linkpath)
rpkt = statusFromError(p.ID, err)
case *sshFxpClosePacket:
log.Println("pkt: close handle: ", p.Handle)
rpkt = statusFromError(p.ID, s.closeHandle(p.Handle))
case *sshFxpReadlinkPacket:
- log.Println("pkt: read: ", p.Path)
- f, err := os.Readlink(toLocalPath(p.Path))
+ log.Println("pkt: readlink: ", p.Path)
rpkt = &sshFxpNamePacket{
ID: p.ID,
NameAttrs: []*sshFxpNameAttr{
{
- Name: f,
- LongName: f,
+ Name: p.Path,
+ LongName: p.Path,
Attrs: emptyFileStat,
},
},
}
- if err != nil {
- rpkt = statusFromError(p.ID, err)
- }
case *sshFxpRealpathPacket:
log.Println("pkt: absolute path: ", p.Path)
f := s3.NewS3Path(p.Path).Path
@@ -288,7 +284,7 @@ func handlePacket(s *Server, p orderedRequest) error {
case *sshFxpReadPacket:
var err error = EBADF
f, ok := s.getHandle(p.Handle)
- log.Println("pkt: read handle: ", p.Handle, f.Path.Path)
+ //log.Println("pkt: read handle: ", p.Handle, f.Path.Path)
if ok {
err = nil
data := p.getDataSlice(s.pktMgr.alloc, orderID)
@@ -309,7 +305,7 @@ func handlePacket(s *Server, p orderedRequest) error {
}
case *sshFxpWritePacket:
- log.Println("pkt: write handle: ", p.Handle, ", Offset: ", p.Offset)
+ //log.Println("pkt: write handle: ", p.Handle, ", Offset: ", p.Offset)
f, ok := s.getHandle(p.Handle)
var err error = EBADF
if ok {
@@ -324,7 +320,7 @@ func handlePacket(s *Server, p orderedRequest) error {
rpkt = p.respond(s)
}
case serverRespondablePacket:
- log.Println("pkt: respondable")
+ //log.Println("pkt: respondable")
rpkt = p.respond(s)
default:
return fmt.Errorf("unexpected packet type %T", p)
@@ -477,7 +473,7 @@ func (p *sshFxpOpenPacket) respond(svr *Server) responsePacket {
}
func (p *sshFxpReaddirPacket) respond(svr *Server) responsePacket {
- log.Println("pkt: readdir: ", p.Handle)
+ //log.Println("pkt: readdir: ", p.Handle)
f, ok := svr.getHandle(p.Handle)
if !ok {
return statusFromError(p.ID, EBADF)