icetee / node-ftp

An FTP client module for node.js
MIT License
25 stars 16 forks source link

ftps put file #9

Open Kellendros007 opened 6 years ago

Kellendros007 commented 6 years ago

In some cases when I rewrite file on ftps server file get size 0 bite. When I analyse your code I found error, in "connection.js -> FTP.prototype._store -> _pasv -> sendStore -> _send -> if (code === 150 || code === 125) -> if (isBuffer)" you send data without check that secure connection was established. As a result data not transferred to server server give code 150 and I was not see code 226. I make work around with setInterval and now it working good, but I think that my code so bad and it will be good if you resolve this issues because file with size 0 is not good.

PS. sorry for my bad English.

amdolan-ngl commented 5 years ago

@Kellendros007 Can you show how you fixed it?

Kellendros007 commented 5 years ago

@Kellendros007 Can you show how you fixed it?

I was change from

if (isBuffer) //line 1066 dest.end(input); //line 1067

to

if (isBuffer){ var EstablishIntervalTime = 0; var EstablishIntervalMax = 5000; var EstablishIntervalStep = 10; var EstablishInterval = setInterval(function(){ EstablishIntervalTime+=EstablishIntervalStep; if (dest._secureEstablished){ dest.end(input); clearInterval(EstablishInterval); } else if (EstablishIntervalTime>EstablishIntervalMax) { clearInterval(EstablishInterval); throw new Error("Connection not established"); } }, EstablishIntervalStep); }