-
Notifications
You must be signed in to change notification settings - Fork 380
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
SFTP Test Server #505
Comments
We probably need more source code to figure out what could be going on. |
Sure. I just copy-and-pasted the source code of "go-sftp-server" in a new Golang project and i executed it with "go run ...". `func upload(client *sftp.Client, localFilePath string, remoteFilePath string) error {
}` |
Hi, I think the example sftp server only accepts/serves a single connection. This could be the issue. In your sample code I read:
I'm not sure about the server implementation, but if you use the request-server it works fine (I added this feature a while ago), you can easily check this feature using SFTPGo |
Hi @drakkan, |
@c4r3 the examples only handle a single connection, if you connect twice the second connection will not work. I guess this is the problem when you connect with CyberDuck (I've never used it but FileZilla, for example, opens a new connection when you upload a file). The server implementation is a ready to use implementation that uses the local filesystem, the request server allows to implement your custom logic. SFTPGo is a full-featured SFTP server that uses request server implementation, handles multiple connections, storage backends other than the local filesystem etc. It's probably overkill for your use case, but by testing with it you can figure out what the library really allows. |
Normally, you would not put this in an |
Hi @puellanivis, |
In that case, you’ve made a mistake. The
The client needs to stay open for the entirety of your operation business logic. You only |
I agree but i omitted one detail: it's just the first implementation, i'll share the same instance of the client to avoid "opening and closing" each time. Maybe the issue is due to the capability of the server to manage just a connection, i have to test it. |
I’m a little confused now… if that is out-of-scope, then we need to see your server code, right? |
When i had the first "connection lost" of my upload method, i started to check if the SFTP test implementation worked fine. |
Do you have any of the output logs from the server when it is running? |
Sure, this is the stdout in my shell (i enabled the debug mode with the corresponding flag). `
As you can see the last log message is "accepted: true" into the for loop on the chan of incoming ssh requests. |
Can you try with the OpenSSH Plus, I see that you’re connecting with |
Yeah sorry, i just changed the defauuser e password. I'll check with OpenSSH as soon as possibile. |
Yeah, this is turning into something really weird, as I’m unable to reproduce. |
@puellanivis if you start the example server and you connect with FileZilla the connection will work and FileZilla will list the files.
this happens because the example code just handle a single connection and filezilla tries to open a new connection to upload the file. I guess Cuberduck works the same way |
i agree. Thank you guys for all. I precisely started with the idea of avoid this kind of issues in production. |
I had no time this evening to do other testing, so i have no updates. |
No, I haven’t tried CyberDuck myself. 🤔 I hate to install all the various SFTP client applications, but I suppose its probably inevitable at some point. 🤣 |
I created a simple SFTP Test server to achive some assertions with my unittest of my SFTP client.
I start the server in a dedicated go routine at the startup, then i execute all my unittest and i close it on teardown phase.
The connection is established, but i had an issue during the upload of the file: when the client "open" the remote file i had an error of "connection lost".
There are few lines of code involved:
dstFile, err := client.OpenFile(remoteFilePath, (os.O_WRONLY | os.O_CREATE | os.O_TRUNC)) if err != nil { return fmt.Errorf("unable to open remote file: %v", err) }
The error is: "unable to open remote file: connection lost".
Due to this issue i created a new dedicated project with just the SFTP server (the same of the sftp/examples/go-sftp-server/) and i used CyberDuck to test the uploading of the file.
Cyberduck can connect correctly to the server but when i try to upload a file the connection hangs, nothing happens and it terminates with timeout.
I'm not understand what's wrong, any ideas?
The text was updated successfully, but these errors were encountered: