0

I'm trying to close my ftp connection to some ftp and it just hangs... forever!

  • it only happens against 1 FTP server, so I'm assuming there's something bad setup with that server. Code works fine against other servers.
  • only happens when the file I'm uploading is huge (180mb). Connection closes fine when file(s) are small.
  • destination FTP server is running 220 ProFTPD 1.3.4a Server (Debian)
  • For the large file, start time: 15:53:18.701. End time: 16:00:22.179; Roughly 7 mins.
  • The 180MB file is 100% uploaded .. so it's when I'm trying to close the connection to complete the transfer and then continue in my code.

Here's the code:

using (var ftpStream = await ftpWebRequest.GetRequestStreamAsync())
        {
            await inputStream.CopyToAsync(ftpStream);

            _loggingService.Debug("Closing service....");
            ftpStream.Close();
            _loggingService.Debug("Closed..");
        }

Yes, I know I don't really need to call .Close(); because I'm in a using statement but I did this to pinpoint to problem.

halfer
  • 19,824
  • 17
  • 99
  • 186
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • What does your method signature look like? – monstertjie_za May 03 '16 at 06:29
  • [Enable logging](http://stackoverflow.com/q/9664650/850848) and show is the log. + How long did you try to wait? + For a simplicity, can you debug this with synchronous streams? – Martin Prikryl May 03 '16 at 06:47
  • Are you using FTP over SSL by any chance? – Castaglia May 03 '16 at 22:20
  • @Castaglian nope - it's not. – Pure.Krome May 04 '16 at 00:21
  • @MartinPrikryl dude. Dude! awesome suggestion!! So I turned it on and started seeing the `FtpWebRequest` low level traffic .. but nothing stood out. I saw the BeginFtpWebRequest or whatever it was called for the STOR and then nothing really else. Mind you, this is in an Azure Web Job so there was all this frickin webjob-http logging noise/spam I had to fight/try-and-filter out ... – Pure.Krome May 04 '16 at 00:23
  • Can you show us the log anyway? Preferably using the synchronous streams. And a log for a successful transfer for a comparison. + Again, how long did you try to wait? – Martin Prikryl May 04 '16 at 05:48
  • I'll try and get a log in the next day or so. it's hard with all the noise from the webjob 'heartbeat home' http calls. I think i waited about 20 - 30 mins. i think? I also have `KeepAlive` = true on. i'll try and post some log data including the initial handshake etc. – Pure.Krome May 04 '16 at 06:22

1 Answers1

0

Try this:

// after finished uploading
ftpWebRequest.Abort();   // <=== MAGIC PART
// before ftpStream.Close()

From here (and also this SO answer).

Shaul Behr
  • 36,951
  • 69
  • 249
  • 387