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

FtpUpload Buffer Size #7

Closed
Hauraky opened this issue Mar 15, 2020 · 12 comments · Fixed by #11 or #12
Closed

FtpUpload Buffer Size #7

Hauraky opened this issue Mar 15, 2020 · 12 comments · Fixed by #11 or #12
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Hauraky
Copy link

Hauraky commented Mar 15, 2020

Hi,
I am using ftpclient to upload files from my devices to my FTP site.
Everything works fine, but when the transferred file is small (minus 1 Mb), I found a damaged partial file on my FTP site.
Below my code:
bool uploadFile(String PathFileName) {
FTPClient ftpClient = new FTPClient(Host, user: Username, pass: Password);
try {
ftpClient.connect();
ftpClient.uploadFile(new File(PathFileName));
sleep(Duration(seconds: 5));
ftpClient.disconnect();
return true;
} catch (ex) {
debugPrint(ex.toString());
return false;
}
}

To workaround I insert a sleep before Disconnect method.
The right solution is to change the Buffer Size in the class FileUpload {
static const int _BUFFER_SIZE = 1024 * 1024;
I tried to set the _BUFFER_SIZE = 1024; and in this way I don't need to use the sleep.
Seems that the function uploadFile in your class FileUpload exit before transfer is complete. So when my program call disconnect method because it think the transfer is complete, it drops the transfer. I hope the description of my issue is clear.
I'am using android 8, ftpclient: ^0.5.0

@virtualmarc virtualmarc added the bug Something isn't working label Mar 15, 2020
@virtualmarc
Copy link
Contributor

If the uploaded file is smaller than the buffer size, the buffer size should be adjusted to the file size.

Will be fixed in the next release!

@virtualmarc virtualmarc self-assigned this Mar 16, 2020
@virtualmarc
Copy link
Contributor

I saw that the buffer size is already adjusted if the file or part is smaller.

I tried to reproduce it but my upload worked. Same checksum on client and server.

I tested it with a binary file with the following sizes:

  • 1178 B
  • 125 B
  • 116738 B

Could you please tell me the exact size of your file?

@virtualmarc virtualmarc added the help wanted Extra attention is needed label Mar 16, 2020
@Hauraky
Copy link
Author

Hauraky commented Mar 16, 2020

The file size is 126.976 byte

@virtualmarc virtualmarc removed the help wanted Extra attention is needed label Mar 16, 2020
@virtualmarc
Copy link
Contributor

Sorry I'm not able to reproduce it, even with this size.

Since it's smaller than the buffer size, the buffer size is adjusted correctly and the file is uploaded all at once.

@virtualmarc virtualmarc added the help wanted Extra attention is needed label Mar 16, 2020
@Hauraky
Copy link
Author

Hauraky commented Mar 16, 2020

How can I help you?
Do you think that is server problem?
I can create to you a temp account to my ftp site.
Then, I do an other issue about listDirectoryContent. This method goes in timeout.
Let me know

@virtualmarc
Copy link
Contributor

I published a new Version (0.6.0) which adds a configurable buffer size as a temporary workaround.

Can you tell us what FTP Server software you use?
This could help us with testing against it. (We only tested the lib with ProFTPd)
If I can't reproduce it with the same FTP Server you use I'll come back to the offer with the temp account on your ftp site.

@virtualmarc
Copy link
Contributor

As stated in #8 I'll set up a Pure-FTPd testsystem to check against it.

@virtualmarc
Copy link
Contributor

virtualmarc commented Mar 17, 2020

Temporary workaround with the configurable buffersize did not work.

I will investigate this further.

@wwwdata
Copy link
Contributor

wwwdata commented Apr 17, 2020

I can confirm this is broken. Whenever I want to upload a jpeg image with like 1-2 megabytes, it arrives in a broken state on the server. Did you manage to fix it already?

@wwwdata
Copy link
Contributor

wwwdata commented Apr 18, 2020

Hey guys, I opened a small PR. Actually a simple flush was everything that was needed in order to make sure that all the data was piped to the FTP socket.

@virtualmarc
Copy link
Contributor

Hey guys, I opened a small PR. Actually a simple flush was everything that was needed in order to make sure that all the data was piped to the FTP socket.

Thank you! That solution was too easy to notice ...

I'll publish a new Version now.

@wwwdata
Copy link
Contributor

wwwdata commented Apr 18, 2020

I am sorry, I was not testing this correctly. After my "fix" it just worked a couple of times in a row. But apparently, it is not fixed. Now I got corrupted files again, so there must be something else that is going wrong.

I am debugging it further. Also changing it from this raw socket to a normal one and piping a file read stream into a normal socket, waiting for it to flush and so on is not fixing things :P So the error must be at some other place than the socket that uploads the data. Maybe the disconnect from the server is still too early.

What was the reason you were only using sync methods by the way for this plugin?

@virtualmarc virtualmarc linked a pull request Apr 19, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
3 participants